-
Notifications
You must be signed in to change notification settings - Fork 55
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
Support using the merge ref instead of the head ref in a pull request #601
Support using the merge ref instead of the head ref in a pull request #601
Conversation
Build succeeded.
|
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.
so far so good! can we have this for gitlab as well? tests would be very much appreciated here :)
ogr/abstract.py
Outdated
@@ -404,6 +404,14 @@ def patch(self) -> bytes: | |||
def head_commit(self) -> str: | |||
raise NotImplementedError | |||
|
|||
@property | |||
def merge_commit_sha(self) -> str: | |||
raise NotImplementedError |
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.
raise NotImplementedError | |
raise NotImplementedError() |
an instance should be raised instead of the class
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.
It does not matter, you can use class or and instance: https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement :
raise evaluates the first expression as the exception object. It must be either a subclass or an instance of BaseException. If it is a class, the exception instance will be obtained when needed by instantiating the class with no arguments.
I know it works but this was the first time I've checked it in the docs..;) So, thanks for pointing that out!
But it would be nice to unify this across the project.
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.
As I mentioned on IRC, in GitHub, 'mergeable' is a boolean, while in
GitLab, the closest thing seems to be merge_status which, if I'm
reading the doc (https://docs.gitlab.com/ee/api/merge_requests.html)
correctly, is a string that can have several values including "unchecked",
"checking", "can_be_merged", and "cannot_be_merged".
I went on to say that "...Maybe the answer is to map GL's
"can_be_merged" to 'True' and everything else to 'False'" and Tomas
like this idea, at least provisionally.
OR we could map "can_be_merged" to True, "cannot_be_merged" to False,
and everything else to None.
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.
In the Packit Arthitecture meeting on 06/15/2021, we decided that we
would present GitLab-like behavior, and map GitHub behavior onto it.
This means that we will provide a (GitLab-like) 'merge_status' @Property
instead of (GitHub-like) 'mergeable', with GitHub's
'mergeable' values mapped as follows:
mergeable | => merge_status |
---|---|
True | "can_be_merged" |
False | "cannot_be_merged" |
<> | "unchecked" |
<> | "checking" |
<> | "cannot_be_merged_recheck" |
6419e72
to
5d3f5b5
Compare
Build succeeded.
|
ogr/services/github/pull_request.py
Outdated
return self._raw_pr.mergeable | ||
def merge_status(self) -> str: | ||
if self._raw_pr.mergeable: | ||
return "can_be_merged" |
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 thought you meant an enumeration like this for commit statuses.
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.
agreed, an enum here would be much better
Build failed.
|
2e86a9c
to
9906d16
Compare
Build failed.
|
On my last run, I got some errors that I do not understand: E OSError: You are in Requre write mode, please set proper GITHUB_TOKEN env variables See below. I have a GITHUB_TOKEN defined in my environment (set in ~/.bashrc); ____________________ PullRequests.test_merge_commit_sha_240 ____________________ self = <tests.integration.github.test_pull_requests.PullRequests testMethod=test_merge_commit_sha_240>
E OSError: You are in Requre write mode, please set proper GITHUB_TOKEN env variables class = <class 'tests.integration.github.base.GithubTests'> |
I expect that, once we get the aforementioned issues and errors straightened out, BTW, 'make check' takes about 10 minutes in my experience; less if the test domain %%% TEST_TARGET=./tests/integration/github/ make check |
@bcrocker15 Hi Ben, EDIT: issue is more complicated and causing, that currently tests does not test anything and there may be false negative results and may hide regressions (see: https://github.com/packit/requre/pull/206/files#diff-013a26cea674b9569659c20d86db214c9d25108da1a8c54c5bab6a265a442619R64 ) |
Build failed.
|
I'm anticipating a question like, "Why didn't I combine all my
The answer is that it appears to break pytest; I see this in the log (changed > to -> ______________________ PullRequests.test_merge_commit_sha ______________________ self = <tests.integration.github.test_pull_requests.PullRequests testMethod=test_merge_commit_sha>
-> pr111 = self.hello_world_project.get_pr(111) pr240 = <GithubPullRequest(title='testing-farm: migrate to official TMT format', id=240, status='merged', url='https://github....n='Not sure w...', author='thrix', source_branch='fix-fmf-tests', target_branch='main', created='2021-02-17 17:10:34')> ... E requre.exceptions.ItemNotInStorage: Keys not in storage:/home/bcrocker/Work/packit-all/ogr/tests/integration/github/test_data/test_pull_requests/PullRequests.test_merge_commit_sha.yaml Matched: ['requests.sessions', 'send', 'GET'], Missing: ['https://api.github.com:443/repos/packit/hello-world/pulls/111'] |
@bcrocker15 It can be combined together, it should no be any issue. Just be sure that when you do that. You have to regenerate the data files. because data file is connected with one test. so that In case you'll extend one test you have to regenerate the file. There is bigger reason why it is solved in this way: as example you can have command like with creating new PR
Another issue could be when you reorder commands calls (just in some cases), it may also lead to need of regenereate data (it depends on stored keys for the data and how data are sent to server) e.g. in case some requests to github differs (stored is HTTP method and URL) so that in case it differs just by sent data, it will be concatenated inside one list, so that in case you will change order of commands data will be server in reversed order. And it seems that you've used old data file, beucase pr240 is there but pr11 is not stored there.
|
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.
Looks good! Let's have the enum for the status and I believe we're good to go
ogr/services/github/pull_request.py
Outdated
return self._raw_pr.mergeable | ||
def merge_status(self) -> str: | ||
if self._raw_pr.mergeable: | ||
return "can_be_merged" |
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.
agreed, an enum here would be much better
Build failed.
|
b0cf12e
to
0005f29
Compare
Build failed.
|
0005f29
to
2301bf8
Compare
Build failed.
|
Build failed.
|
6bf8f63
to
17dcfa1
Compare
Build failed.
|
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.
Thanks for the progress!
Regarding the requre responses, I think we are doing too much here:
- regenerating some response files (not needed probably)
- renaming the response files to match the new (shorter) naming scheme (can be done in a separate commit or PR)
- response files for the tests you've created (yes, those need to be here and are the only needed changes (specifically additions) of response files in this PR)
ogr/abstract.py
Outdated
class CommitStatus(Enum): | ||
pending = 1 | ||
success = 2 | ||
failure = 3 | ||
error = 4 | ||
canceled = 5 | ||
running = 6 | ||
mergeable = 7 | ||
notmergeable = 8 |
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 not sure merging those two use-cases together is a good idea. I can't think of any use where both mergeable
and success
/failure
/.. makes sense.
I think others suggested using a new enum and get inspired by CommitStatus
. Not to reuse CommitStatus
.
ogr/services/gitlab/pull_request.py
Outdated
@property | ||
def merge_commit_status(self) -> CommitStatus: | ||
if self._raw_pr.merge_status == "can_be_merged": | ||
return CommitStatus.mergeable | ||
else: | ||
return CommitStatus.notmergeable |
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.
Here, we can convert all possible values to the newly created Enum
. As we discussed at the arch meeting, we want to differentiate e.g. pending
and notmergeable
. So, I would not treat all statuses that are not can_be_merged
as notmergeable
since it can't easily be a false statement.
17dcfa1
to
4f2bfac
Compare
Build failed.
|
4f2bfac
to
ad7e67d
Compare
Build failed.
|
I did a 'git reset' to get back to the state before I attempted to =================================== FAILURES =================================== self = <tests.integration.github.test_pull_requests.PullRequests testMethod=test_merge_commit_sha>
-> raise EnvironmentError( class = <class 'tests.integration.github.base.GithubTests'> tests/integration/github/base.py:15: OSError self = <tests.integration.gitlab.test_pull_requests.PullRequests testMethod=test_merge_commit_sha>
-> raise EnvironmentError( class = <class 'tests.integration.gitlab.base.GitlabTests'> tests/integration/gitlab/base.py:16: OSError and the requre-0.8.1 update did NOT seem to help. |
ad7e67d
to
b0a1692
Compare
Build failed.
|
b0a1692
to
b0eb598
Compare
Build failed.
|
Build succeeded.
|
I implemented code changes as suggested by Frantisek, making the With two new test_data files, note success on all Zuul tests! |
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.
\o/
def test_merge_commit_sha(self): | ||
pr1 = self.project.get_pr(1) | ||
pr12 = self.project.get_pr(12) | ||
pr19 = self.project.get_pr(19) | ||
assert pr1.merge_commit_sha == "101a42bbbe174d04b465d49caf274dc3b4defeca" | ||
assert pr1.merge_commit_status == MergeCommitStatus.can_be_merged | ||
assert pr12.merge_commit_sha == "f6de56d97ec3ec74cd5194e79175162d9f969195" | ||
assert pr12.merge_commit_status == MergeCommitStatus.can_be_merged | ||
assert pr19.merge_commit_sha == "b8e18207cfdad954f1b3a96db34d0706b272e6cf" | ||
assert pr19.merge_commit_status == MergeCommitStatus.can_be_merged |
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.
What about having some example with MergeCommitStatus.cannot_be_merged
?
38c8e98
to
056f9a3
Compare
Build failed.
|
recheck |
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.
Just one change-request, otherwise LGTM.
Can you please take care of finishing this?
ogr/services/gitlab/pull_request.py
Outdated
@property | ||
def merge_commit_status(self) -> MergeCommitStatus: | ||
status = self._raw_pr.merge_status | ||
assert status in self._merge_commit_status |
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.
assert status in self._merge_commit_status |
Using assert
in the production code is not expected -- python, when run in the optimise mode, ignores such commands so we can't really on the execution of this.
Note that you are checking this one line bellow so it's not needed here.
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.
Fixed by myself.
Build failed.
|
Add merge_commit_sha and merge_commit_status properties to GithubPullRequest class (and PullRequest superclass); merge_commit_status returns a MergeCommitStatus. GitHub's 'mergeable' boolean maps to MergeCommitStatus.can_be_merged (true) or MergeCommitStatus.cannot_be_merged (false). GitLab's 'merge_status' string values map to MergeCommitStatus values verbatim. New test_pull_requests.py:test_merge_commit_sha methods for GitHub and GitLab. In Makefile, pass GITHUB_TOKEN, GITLAB_TOKEN in check-in-container OGR issue packit#584. Signed-off-by: Ben Crocker <[email protected]>
Signed-off-by: Ben Crocker <[email protected]>
The assert code is ignored when Python is run in the optimised mode. Signed-off-by: Frantisek Lachman <[email protected]>
056f9a3
to
6e5bf1a
Compare
I've rebased the PR myself so we can merge it. |
Build succeeded.
|
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.
@bcrocker15 thanks for working on this!
I've just rebased the PR for you and add one commit with a small fix I've mentioned in the comments but you still have the credits..;)
Build succeeded (gate pipeline).
|
Add merge_commit_sha and mergeable properties to GithubPullRequest class
(and PullRequest superclass).
OGR issue #584.
Signed-off-by: Ben Crocker [email protected]