Class: Shipit::Cli::Work

Inherits:
Object
  • Object
show all
Defined in:
lib/shipit/cli/work.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issue_id, global_options) ⇒ Work

Returns a new instance of Work.

Parameters:

  • issue_id (Integer)

    The issue GitLab IID

  • target_branch (String)

    “master”, “develop”…

  • global_options (Hash)

    A hash of options

    • dry_run : If true will not perform the commands

    • client : an instance of the GitLab client



14
15
16
17
18
# File 'lib/shipit/cli/work.rb', line 14

def initialize(issue_id, global_options)
  @issue_id       = issue_id
  @global_options = global_options
  @client = global_options.fetch(:client)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/shipit/cli/work.rb', line 7

def client
  @client
end

#global_optionsObject (readonly)

Returns the value of attribute global_options.



7
8
9
# File 'lib/shipit/cli/work.rb', line 7

def global_options
  @global_options
end

#issue_idObject (readonly)

Returns the value of attribute issue_id.



7
8
9
# File 'lib/shipit/cli/work.rb', line 7

def issue_id
  @issue_id
end

Instance Method Details

#dry_run?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/shipit/cli/work.rb', line 44

def dry_run?
  global_options["dry_run"] == true
end

#perform(target_branch) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/shipit/cli/work.rb', line 25

def perform(target_branch)
  # 1. Load issue
  issue = fetch_remote_issue(issue_id).to_hash
  # 2. Validate issue
  validate_issue(issue)
  # 3. Add additional issue attributes
  enhanced_issue = enhance_issue(issue, target_branch)
  # 4. Create remote branch & checkout
  create_source_branch(enhanced_issue)
  # 5. Create merge request
  create_merge_request(enhanced_issue)
  # 6. Motivation!
  puts ""
  Shipit::Cli.ascii
rescue => e
  exit_now! e
end