Module: Github

Includes:
HTTParty
Defined in:
lib/github.rb

Class Method Summary collapse

Class Method Details

.check_environmentObject



13
14
15
16
17
18
# File 'lib/github.rb', line 13

def self.check_environment
  if GITHUB_USERNAME == nil || GITHUB_TOKEN == nil
    raise "environment variables not set. Please check that you have the following set...\
    \nGITHUB_USERNAME\nGITHUB_TOKEN"
  end
end

.format(stories) ⇒ Object

formats the output of stories



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/github.rb', line 57

def self.format(stories)
  result_string = ""
  stories.each do |story|
    result_string += "#{story['number']}:"
    result_string += "#{story['title']}"
    result_string += "\n"
  end

  # clean up any troublesome chars
  result_string.gsub!('`', ' ') || result_string
end

.get_release_notes(gh_pr_ids) ⇒ Object



27
28
29
30
# File 'lib/github.rb', line 27

def self.get_release_notes gh_pr_ids
  stories = get_release_notes_array gh_pr_ids
  result_string = format stories
end

.get_release_notes_array(gh_pr_ids) ⇒ Object



32
33
34
35
# File 'lib/github.rb', line 32

def self.get_release_notes_array gh_pr_ids
  check_environment
  get_stories gh_pr_ids
end

.get_stories(array_of_pr_ids) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/github.rb', line 47

def self.get_stories(array_of_pr_ids)
  stories = []
  return [] unless array_of_pr_ids
  array_of_pr_ids.each do |id|
    stories<< get_story(id)
  end
  stories
end

.get_story(pr_id) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/github.rb', line 37

def self.get_story(pr_id)
  set_repo_info
  story_response = self.get("#{GITHUB_BASE_URL}/repos/#{@repo_name}/#{@app_name}/pulls/#{pr_id}?access_token=#{GITHUB_TOKEN}",
                             {
                               :headers => { 'User-Agent' => GITHUB_USERNAME, 'Content-Type' => 'application/json', 'Accept' => 'application/json'}
                             })
  return story_response.parsed_response unless story_response.parsed_response.nil? || story_response.parsed_response["code"] == "error"
  {"id" => story_id, "name" => "PR not found in github"}
end

.set_repo_infoObject



20
21
22
23
24
25
# File 'lib/github.rb', line 20

def self.set_repo_info
  cmd = "git remote -v |grep origin"
  repo_info = `#{cmd}`
  @repo_name = repo_info.scan(/\:(.*)\//).uniq.flatten.first
  @app_name = repo_info.scan(/\/(.*)\.git/).uniq.flatten.first
end