Class: GitlabAwesomeRelease::Project
- Inherits:
-
Object
- Object
- GitlabAwesomeRelease::Project
- Defined in:
- lib/gitlab_awesome_release/project.rb
Constant Summary collapse
- PER_PAGE =
100
Instance Method Summary collapse
- #add_merge_request_label(mr, label) ⇒ Object
-
#all_tag_names ⇒ Array<String>
all tag names order by author date.
- #generate_change_log(oldest_tag, newest_tag) ⇒ String
- #generate_heading(title) ⇒ Object
-
#generate_release_note(from, to, title: nil) ⇒ String
generate release note between from...to.
-
#initialize(api_endpoint:, private_token:, project_name:, allow_tag_format:, merge_request_commit_format:, logger:) ⇒ Project
constructor
A new instance of Project.
-
#merge_request(iid) ⇒ Object
find MergeRequest with iid.
-
#merge_request_iids_between(from, to) ⇒ Array<Integer>
find merge requests between from...to.
-
#merge_request_summary(iid) ⇒ String
Markdown text.
- #merge_requests_summary_between(from, to) ⇒ Object
- #release_tag_names ⇒ Array<String>
- #web_url ⇒ Object
Constructor Details
#initialize(api_endpoint:, private_token:, project_name:, allow_tag_format:, merge_request_commit_format:, logger:) ⇒ Project
Returns a new instance of Project.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gitlab_awesome_release/project.rb', line 15 def initialize(api_endpoint:, private_token:, project_name:, allow_tag_format:, merge_request_commit_format:, logger:) Gitlab.configure do |config| config.endpoint = api_endpoint config.private_token = private_token end @project_name = project_name @allow_tag_format = allow_tag_format @merge_request_commit_format = merge_request_commit_format @logger = logger end |
Instance Method Details
#add_merge_request_label(mr, label) ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/gitlab_awesome_release/project.rb', line 130 def add_merge_request_label(mr, label) labels = mr.labels labels << label Gitlab.update_merge_request(@project_name, mr.iid, labels: labels.uniq.join(",")) @logger.info "Add [#{label}] to !#{mr.iid} #{mr.title}" end |
#all_tag_names ⇒ Array<String>
all tag names order by author date
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gitlab_awesome_release/project.rb', line 32 def all_tag_names return @all_tag_names if @all_tag_names @logger.info "fetch git tags" = with_paging do |params| Gitlab.(@project_name, params) end # avoid SEGV on ruby 2.6.0 # https://bugs.ruby-lang.org/issues/15489 @all_tag_names = .sort_by {|tag| tag.commit. }.map {|tag| tag.name } end |
#generate_change_log(oldest_tag, newest_tag) ⇒ String
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/gitlab_awesome_release/project.rb', line 54 def generate_change_log(oldest_tag, newest_tag) release_notes = [] release_notes << generate_heading(oldest_tag) if oldest_tag == release_tag_names.first release_tag_names.within(oldest_tag, newest_tag).each_cons(2) do |from, to| release_notes << generate_release_note(from, to) end release_notes << generate_release_note(newest_tag, "HEAD", title: "Unreleased") if newest_tag == release_tag_names.last changelog = release_notes.reverse.each_with_object("") do |release_note, str| str << release_note str << "\n" end changelog << <<-MARKDOWN *This Change Log was automatically generated by [gitlab_awesome_release](https://gitlab.com/sue445/gitlab_awesome_release)* MARKDOWN changelog end |
#generate_heading(title) ⇒ Object
95 96 97 |
# File 'lib/gitlab_awesome_release/project.rb', line 95 def generate_heading(title) "## #{title}\n" end |
#generate_release_note(from, to, title: nil) ⇒ String
generate release note between from...to
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/gitlab_awesome_release/project.rb', line 80 def generate_release_note(from, to, title: nil) @logger.info "generate release note (#{from}...#{to})" title ||= to summary = merge_requests_summary_between(from, to) header = generate_heading(title) header << <<-MARKDOWN [full changelog](#{web_url}/compare/#{from}...#{to}) MARKDOWN header + summary end |
#merge_request(iid) ⇒ Object
find MergeRequest with iid
126 127 128 |
# File 'lib/gitlab_awesome_release/project.rb', line 126 def merge_request(iid) Gitlab.merge_request(@project_name, iid) end |
#merge_request_iids_between(from, to) ⇒ Array<Integer>
find merge requests between from...to
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/gitlab_awesome_release/project.rb', line 103 def merge_request_iids_between(from, to) commits = Gitlab.repo_compare(@project_name, from, to).commits merge_request_iids = commits.map do |commit| commit["message"] =~ @merge_request_commit_format Regexp.last_match(1) end merge_request_iids.compact.map(&:to_i) end |
#merge_request_summary(iid) ⇒ String
Returns markdown text.
117 118 119 120 121 122 123 |
# File 'lib/gitlab_awesome_release/project.rb', line 117 def merge_request_summary(iid) mr = merge_request(iid) return nil unless mr mr_url = "#{web_url}/merge_requests/#{iid}" "* #{mr.title} [!#{iid}](#{mr_url}) *@#{mr..username}*" end |
#merge_requests_summary_between(from, to) ⇒ Object
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/gitlab_awesome_release/project.rb', line 138 def merge_requests_summary_between(from, to) mr_iids = merge_request_iids_between(from, to) mr_iids.each_with_object("") do |iid, str| begin str << merge_request_summary(iid) + "\n" rescue Gitlab::Error::NotFound # NOTE: suppress error (e.g. other repo's iid) end end end |
#release_tag_names ⇒ Array<String>
47 48 49 |
# File 'lib/gitlab_awesome_release/project.rb', line 47 def release_tag_names all_tag_names.find_all {|tag| tag =~ @allow_tag_format } end |
#web_url ⇒ Object
26 27 28 |
# File 'lib/gitlab_awesome_release/project.rb', line 26 def web_url @web_url ||= Gitlab.project(@project_name).web_url end |