Class: QAT::Devel::GitLab::Client
- Inherits:
-
Object
- Object
- QAT::Devel::GitLab::Client
- Defined in:
- lib/qat/devel/lib/gitlab/client.rb
Overview
Defines methods related to milestones.
Defined Under Namespace
Classes: IssueNotFoundError, IssueReleaseError, MilestoneNotFoundError
Instance Attribute Summary collapse
- #client ⇒ Object readonly
- #issues ⇒ Object readonly
Instance Method Summary collapse
-
#all_milestone_issues_closed?(milestone_id) ⇒ Boolean
Checks closed state on issues of a given milestone id.
-
#create_issue(project, title, options = {}) ⇒ Array
Create a new issue.
-
#create_issue_release(milestone) ⇒ Array
Create a new Issue Release.
-
#create_release_tag(tag_name, release_note) ⇒ Object
Create a release tag.
-
#delete_issue(issue_id) ⇒ Object
Remove a issue.
-
#get_all_milestone_issues(milestone_id) ⇒ Array
Gets the issues of a given milestone id.
-
#get_milestone_id(title) ⇒ Integer
Gets the id of a given milestone title.
-
#get_tags(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of project repository tags.
-
#initialize(endpoint = nil, token = nil, project_id = nil) ⇒ Client
constructor
New QAT::Devel::GitLab::Client.
Constructor Details
#initialize(endpoint = nil, token = nil, project_id = nil) ⇒ Client
New QAT::Devel::GitLab::Client
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 15 def initialize(endpoint = nil, token = nil, project_id = nil) @endpoint = endpoint || ENV['GITLAB_ENDPOINT'] raise ArgumentError.new "No definition of mandatory environment variable 'GITLAB_ENDPOINT'" unless @endpoint @token = token || ENV['GITLAB_TOKEN'] raise ArgumentError.new "No definition of mandatory environment variable 'GITLAB_TOKEN'" unless @token @project_id = project_id || ENV['CI_PROJECT_ID'] raise ArgumentError.new "No definition of mandatory environment variable 'CI_PROJECT_ID'" unless @project_id @client = Gitlab.client endpoint: @endpoint, private_token: @token @issues = {} @milestones = {} end |
Instance Attribute Details
#client ⇒ Object (readonly)
11 12 13 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 11 def client @client end |
#issues ⇒ Object (readonly)
11 12 13 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 11 def issues @issues end |
Instance Method Details
#all_milestone_issues_closed?(milestone_id) ⇒ Boolean
Checks closed state on issues of a given milestone id.
71 72 73 74 75 76 77 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 71 def all_milestone_issues_closed?(milestone_id) issues = get_all_milestone_issues(milestone_id) issues.all? do |issue| issue.state == 'closed' end end |
#create_issue(project, title, options = {}) ⇒ Array
Create a new issue
89 90 91 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 89 def create_issue(project, title, = {}) client.create_issue(project, title, ) end |
#create_issue_release(milestone) ⇒ Array
Create a new Issue Release
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 101 def create_issue_release(milestone) milestone_id = get_milestone_id(milestone) raise(IssueReleaseError, "Found issues with Milestone #{milestone} open!") unless all_milestone_issues_closed?(milestone_id) issues = get_all_milestone_issues(milestone_id) description = nil issues.all? do |issue| i = 0 labels_text = nil issue.labels.all? do |label| if i == 0 labels_text = "~#{label}" i = i + 1 else labels_text = "#{labels_text} ~#{label}" end end description = "" "#{description} - #{labels_text} ##{issue.iid} #{issue.title}" "" end gemspec = Dir.glob('../*.gemspec').first gemspec_spec = Gem::Specification::load(gemspec) gemspec_spec.name.to_s description = "" "## #{gemspec_spec.name.to_s} 2.0.0 **Milestone** \"%#{milestone}\" ### Issues solved in this release #{description} " "" create_issue(@project_id, "Release #{milestone}", = { description: description }) end |
#create_release_tag(tag_name, release_note) ⇒ Object
Create a release tag
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 147 def create_release_tag(tag_name, release_note) # GitLab gem post to create a tag is not correct. # Field containing release note content should be 'release_description' and not 'description' response = client.post("/projects/#{client.url_encode(@project_id)}/repository/tags", body: { tag_name: tag_name, ref: 'master', message: "Release #{tag_name}", release_description: release_note }) puts "\nTAG Creation Response:\n#{response.to_h}\n" end |
#delete_issue(issue_id) ⇒ Object
Remove a issue
140 141 142 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 140 def delete_issue(issue_id) client.delete_issue(@project_id, issue_id) end |
#get_all_milestone_issues(milestone_id) ⇒ Array
Gets the issues of a given milestone id.
57 58 59 60 61 62 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 57 def get_all_milestone_issues(milestone_id) return @issues[milestone_id] if @issues[milestone_id] raise(IssueNotFoundError, "Found 0 issues of Milestone with title #{title}!") unless @issues @issues[milestone_id] = client.milestone_issues(@project_id, milestone_id) end |
#get_milestone_id(title) ⇒ Integer
Gets the id of a given milestone title.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 38 def get_milestone_id(title) # log.debug "Getting milestone id for: #{title}" @milestones = client.milestones(@project_id) milestone = @milestones.select { |milestone| milestone.title == title }.first raise(MilestoneNotFoundError, "Milestone with title #{title} not found in GitLab!") unless milestone milestone.id end |
#get_tags(options = {}) ⇒ Array<Gitlab::ObjectifiedHash>
Gets a list of project repository tags.
165 166 167 |
# File 'lib/qat/devel/lib/gitlab/client.rb', line 165 def ( = {}) client.(@project_id, ) end |