Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rudimentary gitlab support #657

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
736b772
added gitlab fetcher
kreczko May 29, 2018
c2e9ed9
implemented fetch_tags for GITLAB
kreczko May 29, 2018
7e6d1e2
first successful runthrough with gitlab_fetcher
kreczko May 30, 2018
468a7cb
adjusting generator_fetcher to accept pr["merge_commit_sha"] if avail…
kreczko May 30, 2018
df91ce2
added gitlab option
kreczko May 30, 2018
8905121
select correct fetcher depending on gitlab option (default github)
kreczko May 30, 2018
4f24ec0
restricting gitlab fetcher to closed issues
kreczko May 30, 2018
4ef2033
fixed authors in merge_requests for gitlab fetcher
kreczko May 30, 2018
18ede11
fixed typo in generator_fetcher
kreczko May 30, 2018
86b41c0
fixed issues and associated events in gitlab_fetcher
kreczko May 30, 2018
2c261cb
fixed project_id for gitlab_fetcher in the case of forks
kreczko May 30, 2018
e696d2c
fixed events for merge requests in gitlab_fetcher
kreczko May 30, 2018
16fdb8d
fixed merge_commit_sha for older gitlab versions in gitlab_fetcher
kreczko May 30, 2018
d1004f7
separated fetching issues and pull requests as it was causing problem…
kreczko Aug 7, 2018
681c4b4
fix gitlab fetcher for project that have no issues
kreczko Aug 7, 2018
3b5a974
fixed if-logic based on feedback from olleolleolle
kreczko Nov 1, 2018
2a1350f
Github --> Gitlab for GitlabFetcher
kreczko Nov 1, 2018
1de4431
added Gitlab URI example
kreczko Nov 1, 2018
d62e1e1
missing change from Github->Gitlab change: Helper --> GitHubChangelog…
kreczko Nov 1, 2018
d6e257f
CHANGELOG_GITHUB_TOKEN --> CHANGELOG_AUTH_TOKEN for gitlab fetcher
kreczko Nov 1, 2018
264e6ba
fixed RuboCop issues for gitlab_fetcher
kreczko Nov 1, 2018
b13d759
preliminary tests for gitlab_fetcher
kreczko Nov 1, 2018
b1f9d09
added gitlab_changelog_generator
kreczko Nov 1, 2018
0e66b15
Last few Github -> Gitlab conversions
kreczko Nov 1, 2018
182ff69
resolved second batch of feedback from @olleolleolle
kreczko Nov 1, 2018
602a923
Add gitlab to rake task
cdenneen Jan 29, 2020
81b1a9a
Merge pull request #1 from cdenneen/patch-1
kreczko Jan 29, 2020
d5fa89b
Merge remote-tracking branch 'upstream/master' into kreczko-issue-419
cdenneen Jan 29, 2020
faf358a
Merge pull request #2 from cdenneen/kreczko-issue-419
kreczko Jan 30, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bin/
bin/*
!bin/git-generate-changelog
!bin/github_changelog_generator
!bin/gitlab_changelog_generator
pkg/
coverage/
.bundle
Expand Down
5 changes: 5 additions & 0 deletions bin/gitlab_changelog_generator
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /usr/bin/env ruby
olleolleolle marked this conversation as resolved.
Show resolved Hide resolved
# frozen_string_literal: true

require_relative "../lib/gitlab_changelog_generator"
GitLabChangelogGenerator::ChangelogGenerator.new.run
3 changes: 2 additions & 1 deletion lib/github_changelog_generator/generator/generator.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "github_changelog_generator/octo_fetcher"
require "github_changelog_generator/gitlab_fetcher"
require "github_changelog_generator/generator/generator_fetcher"
require "github_changelog_generator/generator/generator_processor"
require "github_changelog_generator/generator/generator_tags"
Expand Down Expand Up @@ -34,7 +35,7 @@ class Generator
def initialize(options = {})
@options = options
@tag_times_hash = {}
@fetcher = GitHubChangelogGenerator::OctoFetcher.new(options)
@fetcher = options[:gitlab] ? GitLabChangelogGenerator::GitlabFetcher.new(options) : GitHubChangelogGenerator::OctoFetcher.new(options)
@sections = []
end

Expand Down
21 changes: 17 additions & 4 deletions lib/github_changelog_generator/generator/generator_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def fetch_events_for_issues_and_pr
print "Fetching events for issues and PR: 0/#{@issues.count + @pull_requests.count}\r" if options[:verbose]

# Async fetching events:
@fetcher.fetch_events_async(@issues + @pull_requests)
@fetcher.fetch_events_async(@issues)
@fetcher.fetch_events_async(@pull_requests)
end

# Async fetching of all tags dates
Expand Down Expand Up @@ -73,9 +74,11 @@ def associate_tagged_prs(tags, prs, total)
# fetch that. See
# https://developer.github.com/v3/pulls/#get-a-single-pull-request vs.
# https://developer.github.com/v3/pulls/#list-pull-requests
if pr["events"] && (event = pr["events"].find { |e| e["event"] == "merged" })
# gitlab API has this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# gitlab API has this
# Compatibility with GitLab API (`pr` can be Merge Request or PR)

merge_commit_sha = try_merge_commit_sha_from_gitlab(pr)
if merge_commit_sha
# Iterate tags.reverse (oldest to newest) to find first tag of each PR.
if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(event["commit_id"]) })
if (oldest_tag = tags.reverse.find { |tag| tag["shas_in_tag"].include?(merge_commit_sha) })
pr["first_occurring_tag"] = oldest_tag["name"]
found = true
i += 1
Expand All @@ -95,6 +98,16 @@ def associate_tagged_prs(tags, prs, total)
end
end

def try_merge_commit_sha_from_gitlab(merge_request)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming here has issues:

  • merge_request argument name - it can be a PR or a Merge Request (e.g. pr_or_merge_request is not an ill-descriptive name for that)
  • the method name #try_merge_commit_sha_from_gitlab obscures that it also processes GitHub data

A method name such as #find_merge_commit_for(pr_or_merge_request) would help maintenance of this.

merge_commit_sha = nil
if merge_request.key?("merge_commit_sha")
merge_commit_sha = merge_request["merge_commit_sha"]
elsif merge_request["events"] && (event = merge_request["events"].find { |e| e["event"] == "merged" })
merge_commit_sha = event["commit_id"]
end
merge_commit_sha
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if is an expression: this can be the whole body.

      if merge_request.key?("merge_commit_sha")
        merge_request["merge_commit_sha"]
      elsif merge_request["events"] && (event = merge_request["events"].find { |e| e["event"] == "merged" })
        event["commit_id"]
      end


# Associate merged PRs by the HEAD of the release branch. If no
# --release-branch was specified, then the github default branch is used.
#
Expand Down Expand Up @@ -157,7 +170,7 @@ def associate_rebase_comment_prs(tags, prs_left, total)
# @param [Hash] issue
def find_closed_date_by_commit(issue)
unless issue["events"].nil?
# if it's PR -> then find "merged event", in case of usual issue -> fond closed date
# if it's PR -> then find "merged event", in case of usual issue -> find closed date
kreczko marked this conversation as resolved.
Show resolved Hide resolved
compare_string = issue["merged_at"].nil? ? "closed" : "merged"
# reverse! - to find latest closed event. (event goes in date order)
issue["events"].reverse!.each do |event|
Expand Down