-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
Add support for GitLab merge requests (MRs) #175
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look too closely at the code, but I wonder if we should lazy load the Gitlab gem + configure it (and the same for Github). That should keep start up time lower.
Thank you @ekohl for the quick feedback. We'll take that immediately into account. We're still at fixing some rough edges of the implementation and doing internal review. |
Relates to #80 (comment). |
db4812d
to
cd3ef1e
Compare
9ee05c7
to
442c9ca
Compare
We have cleaned up the commits and I've consolidated the changes into a single commit. There are still a few topics open: (at least from a first, quick glance)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this and the Github PR code should live in lib/modulesync/pr.rb
. You'd have something like:
module ModuleSync
class PullRequest
def initialize(implementation, token)
@implementation = implementation
case @implementation
when :github
@client = Octokit::Client.new(:access_token => token)
when :gitlab
@client = Gitlab::Client.new(:private_token => token)
else
raise "Unknown implementation #{implementation}"
end
end
def has_pr?(repo_path, source, target)
requests = case @implementation
when :github
@client.pull_requests()
when :gitlab
@client.merge_requests()
end
requests.any?
end
def create_pr(repo_path, source, target)
case @implementation
when :github
@client.pull_request()
when :gitlab
@client.create_merge_request()
end
end
def add_labels_to_pr(repo_path, pr, labels)
# ....
end
end
end
You can also implement PullRequest
and MergeRequest
that implement the same interface.
This keeps lib/modulesync.rb
small. It's already way too big now. An additional benefit is that you cache the client instance which I hope keeps the HTTP connection open. Not sure it does that right now.
.gitignore
Outdated
.ruby-version | ||
.vscode/ | ||
bin/bundle | ||
bin/rspec | ||
modules/ | ||
tmp/ | ||
vendor/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would typically be a separate commit.
Gemfile
Outdated
@@ -2,5 +2,7 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org' | |||
|
|||
gemspec | |||
|
|||
gem 'aruba' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed, looks redundant:
Line 20 in 7202e6b
spec.add_development_dependency 'aruba', '~> 0.14' |
Gemfile
Outdated
gem 'cucumber', '< 3.0' if RUBY_VERSION < '2.1' | ||
gem 'gitlab' # gem 'gitlab', github: 'NARKOZ/gitlab' | ||
gem 'octokit', '~> 4.9' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was there, but I can't explain why because this should be sufficent:
Line 27 in 7202e6b
spec.add_runtime_dependency 'octokit', '~>4.0' |
Gemfile
Outdated
gem 'cucumber', '< 3.0' if RUBY_VERSION < '2.1' | ||
gem 'gitlab' # gem 'gitlab', github: 'NARKOZ/gitlab' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is redundant since it's in the gemspec
442c9ca
to
e4ff51f
Compare
|
Signed-off-by: Manuel Hutter <manuel@vshn.ch>
e1d51b5
to
d0d1ca0
Compare
Still looking into that failing cucumber test, not sure how that's related... Update: noticed that the expected outcome was changed in this PR; I reverted this (was probably changed during implemented; the original implementation of this PR might have changed error behavior) |
Adds the capability of creating GitLab merge requests following the approach currently implemented for GitHub. We try to make the user experience simply by sticking to calling the feature "PR" / "--pr" also for GitLab. Which of both options, GitHub or GitLab, is chosen for processing the user request is determined by the environment variable being set: - GITHUB_TOKEN ... a PR on GitHub will be created - GITLAB_TOKEN ... a MR on GitLab will be created
* Move implementation into separate modules * Lazy-load dependencies * Reuse GitHub/GitLab clients * Add some basic specs for the GitLab implementation Signed-off-by: Manuel Hutter <manuel@vshn.ch>
a50a730
to
4b3ad12
Compare
This commit moves configuration validation (--pr cannot be used without --branch) into initialization. This catches the error early on, before any actual work is done. Signed-off-by: Manuel Hutter <manuel@vshn.ch>
4b3ad12
to
a77b968
Compare
One thing that caught my eye when moving code around: The Gitlab implementation will ensure the configured labels are added to the PR when the PR is created, but will NOT add any labels if there is already an open PR around. The GitHub implementation will always update the existing PR - and fail horribly from looking at the code (note this was already broken before this PR) @ekohl what is the intended behaviour? |
@ekohl Can you clarify? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current code looks like a good solution and an improvement over the current implementation. Just a small comment about the constants, otherwise 👍
I like that it only loads the Github/Gitlab code if a PR was requested which keeps the start up time lower.
lib/modulesync.rb
Outdated
GITHUB_TOKEN = ENV.fetch('GITHUB_TOKEN', '') | ||
|
||
Octokit.configure do |c| | ||
c.api_endpoint = ENV.fetch('GITHUB_BASE_URL', 'https://api.github.com') | ||
end | ||
GITLAB_TOKEN = ENV.fetch('GITLAB_TOKEN', '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can avoid these constants and only use them inline since they're only used in a single place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, totally missed it. Will adjust accordingly
This looks good to me. It's still marked as a draft so let me know when you think it's ready to be merged. |
They are not required on a global scope, so remove them from there Signed-off-by: Manuel Hutter <manuel@vshn.ch> Signed-off-by: Manuel Hutter <manuel@hutter.io>
355f85f
to
bf27fd8
Compare
I broke the check in my last commit, fixed. I think the PR is ready, can you remove the "Draft" status @chamer81 ? I'll open a new Issue to discuss the PR label behaviour. Fixing it should be trivial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with this.
Thanks! |
Thanks everyone for the good collaboration! 🥇 🎊 |
Adds an option to create a gitlab MR.