-
Notifications
You must be signed in to change notification settings - Fork 198
Add 'git-obs staging' command #1961
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
base: master
Are you sure you want to change the base?
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 take it as a draft with upcoming changes.
I've added several comments to the code, I need to test it later.
Also, could you improve commit messages before submitting the final version?
9c8fbfa to
7e70cae
Compare
7e70cae to
55a3fc6
Compare
…argument on python 3.6+
…epo_pull() reusable by allowing setting 'help' argument
55a3fc6 to
b973339
Compare
|
This is the test script I was using:
The commands I ran: |
b973339 to
c767d4f
Compare
c767d4f to
6ee80e8
Compare
…sts into a single project pull request
6ee80e8 to
beb0e43
Compare
|
|
||
| if args.target: | ||
| target_owner, target_repo, target_number = args.target | ||
| pr_obj = gitea_api.PullRequest.get(self.gitea_conn, target_owner, target_repo, target_number) |
Check warning
Code scanning / CodeQL
Variable defined multiple times Warning
redefined
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 days ago
To fix this problem, simply remove the first assignment to pr_obj at line 90. This will not affect the functionality, since the assigned value to pr_obj is never used before it is overwritten with a new assignment later. Be careful to retain the right-hand side (the call to gitea_api.PullRequest.get(...)) if there are any important side effects, but this does not appear to be the case here. Edit the file osc/commands_git/staging_group.py, specifically line 90, to delete this assignment.
| @@ -87,7 +87,6 @@ | ||
|
|
||
| if args.target: | ||
| target_owner, target_repo, target_number = args.target | ||
| pr_obj = gitea_api.PullRequest.get(self.gitea_conn, target_owner, target_repo, target_number) | ||
| # # to update a pull request, we either need to be its creator or an admin in the repo | ||
| # if not (pr_obj._data["base"]["repo"]["permissions"]["admin"] or pr_obj.user == user_obj.login): | ||
| # raise gitea_api.GitObsRuntimeError(f"You don't have sufficient permissions to modify pull request {target_owner}/{target_repo}#{target_number}") |
| # if not (pr_obj._data["base"]["repo"]["permissions"]["admin"] or pr_obj.user == user_obj.login): | ||
| # raise gitea_api.GitObsRuntimeError(f"You don't have sufficient permissions to modify pull request {target_owner}/{target_repo}#{target_number}") |
Check notice
Code scanning / CodeQL
Commented-out code Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 days ago
To resolve this, the commented-out code (lines 91–94, specifically 92–93) should either be removed or, if needed as part of functionality, reinstated as active code. Given there is no explanation for leaving the permissions check commented out, the cleanest fix here is to remove it entirely. However, if the permissions check is required, the code could be reinstated, but that would be a functionality change—and we're directed not to alter existing functionality. Since there are structurally similar commented blocks in two places and no other indication that they're needed, I will simply remove the commented-out code on lines 91–94.
Only lines 91–94 (and similarly, 112–113 for completeness/consistency) should be deleted in file osc/commands_git/staging_group.py. No other files, imports, methods, or definitions are needed for this change.
| @@ -88,9 +88,6 @@ | ||
| if args.target: | ||
| target_owner, target_repo, target_number = args.target | ||
| pr_obj = gitea_api.PullRequest.get(self.gitea_conn, target_owner, target_repo, target_number) | ||
| # # to update a pull request, we either need to be its creator or an admin in the repo | ||
| # if not (pr_obj._data["base"]["repo"]["permissions"]["admin"] or pr_obj.user == user_obj.login): | ||
| # raise gitea_api.GitObsRuntimeError(f"You don't have sufficient permissions to modify pull request {target_owner}/{target_repo}#{target_number}") | ||
|
|
||
| # get pull request data from gitea | ||
| pr_map = {} | ||
| @@ -109,8 +106,6 @@ | ||
| # we don't care about the state of the package pull requests - they can be merged already | ||
| raise gitea_api.GitObsRuntimeError(f"Pull request {owner}/{repo}#{number} is not open (the state is '{pr.pr_obj.state}')") | ||
|
|
||
| # if not (pr.pr_obj._data["base"]["repo"]["permissions"]["admin"] or pr.pr_obj.user == user_obj.login): | ||
| # raise gitea_api.GitObsRuntimeError(f"You don't have sufficient permissions to modify pull request {owner}/{repo}#{number}") | ||
|
|
||
| if gitea_api.StagingPullRequestWrapper.BACKLOG_LABEL not in pr.pr_obj.labels: | ||
| raise gitea_api.GitObsRuntimeError(f"Pull request {owner}/{repo}#{number} is missing the '{gitea_api.StagingPullRequestWrapper.BACKLOG_LABEL}' label.") |
| # if not (pr.pr_obj._data["base"]["repo"]["permissions"]["admin"] or pr.pr_obj.user == user_obj.login): | ||
| # raise gitea_api.GitObsRuntimeError(f"You don't have sufficient permissions to modify pull request {owner}/{repo}#{number}") |
Check notice
Code scanning / CodeQL
Commented-out code Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 days ago
The best way to fix the problem is to remove the commented-out code on line 112 and the following line 113, as they provide no useful documentation and would only confuse future readers. If this check is needed, it should be re-implemented as active code or replaced by a proper docstring or explanatory comment. Since a similar block was already commented out for the target PR, and this block is for the other PRs, but inactive, removing both improves code clarity and does not change functionality. Only lines 112–113 of osc/commands_git/staging_group.py should be edited.
| @@ -109,8 +109,6 @@ | ||
| # we don't care about the state of the package pull requests - they can be merged already | ||
| raise gitea_api.GitObsRuntimeError(f"Pull request {owner}/{repo}#{number} is not open (the state is '{pr.pr_obj.state}')") | ||
|
|
||
| # if not (pr.pr_obj._data["base"]["repo"]["permissions"]["admin"] or pr.pr_obj.user == user_obj.login): | ||
| # raise gitea_api.GitObsRuntimeError(f"You don't have sufficient permissions to modify pull request {owner}/{repo}#{number}") | ||
|
|
||
| if gitea_api.StagingPullRequestWrapper.BACKLOG_LABEL not in pr.pr_obj.labels: | ||
| raise gitea_api.GitObsRuntimeError(f"Pull request {owner}/{repo}#{number} is missing the '{gitea_api.StagingPullRequestWrapper.BACKLOG_LABEL}' label.") |
8a3abd8 to
c1135f3
Compare
c1135f3 to
6ca5061
Compare
| target.pr_obj.set(self.gitea_conn, target_owner, target_repo, target_number, description=target.pr_obj.body) | ||
|
|
||
| for owner, repo, number in args.pr_list: | ||
| pr = pr_map[(owner.lower(), repo.lower(), number)] |
Check notice
Code scanning / CodeQL
Unused local variable Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 12 days ago
To fix the problem, we should remove the assignment to pr on line 63, since the value is never used and the lookup has no side effect. The rest of the code—especially the call to .close()—should remain unchanged, as it does not require pr. No other changes or method/import additions are needed.
- In
osc/commands_git/staging_remove.py, locate line 63:pr = pr_map[(owner.lower(), repo.lower(), number)] - Remove this line entirely, ensuring the rest of the loop (lines 62–66) remains unchanged.
| @@ -60,7 +60,6 @@ | ||
| target.pr_obj.set(self.gitea_conn, target_owner, target_repo, target_number, description=target.pr_obj.body) | ||
|
|
||
| for owner, repo, number in args.pr_list: | ||
| pr = pr_map[(owner.lower(), repo.lower(), number)] | ||
| # close the removed package pull request | ||
| gitea_api.PullRequest.close(self.gitea_conn, owner, repo, number) | ||
|
|
No description provided.