Class: AssistedWorkflow::Addons::Github

Inherits:
Base
  • Object
show all
Defined in:
lib/assisted_workflow/addons/github.rb

Instance Method Summary collapse

Methods inherited from Base

get_required_options, #name, required_options

Constructor Details

#initialize(output, options = {}) ⇒ Github

Returns a new instance of Github.



50
51
52
53
54
55
56
# File 'lib/assisted_workflow/addons/github.rb', line 50

def initialize(output, options = {})
  super
  @client = Octokit::Client.new(:access_token => options["token"])
  
  @repo = options["repository"]
  @username = @client.user.
end

Instance Method Details

#create_pull_request(branch, story) ⇒ Sawyer::Resource

Creates a pull request using current branch changes

Parameters:

  • repo (String)

    Repository name. flaviogranero/assisted_workflow

  • branch (String)

    Branch name. flavio.0001.new_feature

  • story (Story)

    Pivotal story object

Returns:

  • (Sawyer::Resource)

    The newly created pull request



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/assisted_workflow/addons/github.rb', line 64

def create_pull_request(branch, story)
  log "submiting the new pull request"
  base = "master"
  pull_request = if story.is_a? GithubStory
    @client.create_pull_request_for_issue(@repo, base, branch, story.id)
  else
    title = "[##{story.id}] #{story.name}"
    @client.create_pull_request(@repo, base, branch, title, story.description)
  end
  
  if pull_request.nil?
    raise AssistedWorkflow::Error, "error on submiting the pull request"
  end
  
  url = pull_request._links.html.href
  log "new pull request at #{url}"
  url
end

#find_story(story_id) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/assisted_workflow/addons/github.rb', line 83

def find_story(story_id)
  if !story_id.nil?
    log "loading story ##{story_id}"
    issue = @client.issue(@repo, story_id)
    story = GithubStory.new(issue) if issue
    story
  end
end

#finish_story(story, options = {}) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/assisted_workflow/addons/github.rb', line 100

def finish_story(story, options = {})
  log "finishing story ##{story.id}"
  current_labels = story.labels
  current_labels.delete "started"
  current_labels.push "finished"
  @client.reopen_issue(@repo, story.id, :assignee => @username, :labels => current_labels)
end

#pending_stories(options = {}) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/assisted_workflow/addons/github.rb', line 108

def pending_stories(options = {})
  log "loading pending stories"
  opt = {:state => "open"}
  opt[:assignee] = @username unless options[:include_started]
  issues = @client.issues(@repo, opt)
  issues.map do |issue|
    GithubStory.new(issue)
  end
end

#start_story(story, options = {}) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/assisted_workflow/addons/github.rb', line 92

def start_story(story, options = {})
  log "starting story ##{story.id}"
  current_labels = story.labels
  current_labels.delete "finished"
  current_labels.push "started"
  @client.reopen_issue(@repo, story.id, :assignee => @username, :labels => current_labels)
end

#valid?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/assisted_workflow/addons/github.rb', line 118

def valid?
  @client.user_authenticated?
end