Class: Arcanist

Inherits:
Struct
  • Object
show all
Defined in:
lib/arcanist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#certObject

Returns the value of attribute cert

Returns:

  • (Object)

    the current value of cert



7
8
9
# File 'lib/arcanist.rb', line 7

def cert
  @cert
end

#conduit_uriObject

Returns the value of attribute conduit_uri

Returns:

  • (Object)

    the current value of conduit_uri



7
8
9
# File 'lib/arcanist.rb', line 7

def conduit_uri
  @conduit_uri
end

#userObject

Returns the value of attribute user

Returns:

  • (Object)

    the current value of user



7
8
9
# File 'lib/arcanist.rb', line 7

def user
  @user
end

Instance Method Details

#diff(work_dir, callsign, commit: 'HEAD^', differential_id: nil, message: nil, reviewers: '') ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/arcanist.rb', line 9

def diff work_dir, callsign, commit: 'HEAD^', differential_id: nil, message: nil, reviewers: ''
  arcrc = write_arcrc
  temps = [arcrc]
  args = ['--no-ansi', '--conduit-uri', conduit_uri, '--config', "repository.callsign=#{callsign}", '--arcrc-file', arcrc.path]

  if differential_id
    # update existing diff
    args += ['--update', differential_id.to_s, '--message', message || 'Update']
  else
    # create new diff
    tmp = Tempfile.create 'arcmsg'
    tmp.write <<"EOS"
#{message || Git::message(work_dir)}

Test Plan:
N/A (imported by gerricator)

Reviewers: #{[*reviewers].join(', ')}
EOS
    tmp.flush
    temps << tmp
    args += ['--create', '--message-file', tmp.path]
  end

  Dir.chdir work_dir do
    cmd = Shellwords.join(['arc', 'diff', *args, commit])
    result = `#{cmd}`

    if not differential_id
      differential_id = result[/#{File.join(conduit_uri, 'D')}(\d+)/, 1]
    end
  end

  differential_id
ensure
  temps.each do |t|
    File.unlink(t) if t && File.exists?(t)
  end
end