Skip to content

Conversation

@fwag
Copy link
Collaborator

@fwag fwag commented Oct 9, 2025

No description provided.

@fwag fwag marked this pull request as draft October 9, 2025 20:11
Copy link
Contributor

@dmach dmach left a 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?

@dmach dmach changed the title Feature/staging Add 'git-obs staging' command Oct 20, 2025
@dmach
Copy link
Contributor

dmach commented Oct 20, 2025

This is the test script I was using:

  • it has to be run from the git topdir
  • you need to configure git-obs accordingly:
    ./git-obs.py login add testing --url=http://localhost:3000 --user=Admin --token=1111111111111111111111111111111111111111 --ssh-key=$(pwd)/behave/container-files/root/.ssh/admin --set-as-default
#!/bin/sh

set -x

./behave/container-pull.sh
./behave/container-run.sh
podman exec obs-server /usr/bin/systemctl is-system-running --wait


tea repos create --name=_ObsPrj --owner=pool --init --branch=factory --object-format=sha256 --login=admin


git-obs api -X POST /repos/pool/_ObsPrj/labels --data='{"name": "staging/Backlog", "color": "0000cc"}'
git-obs api -X POST /repos/pool/_ObsPrj/labels --data='{"name": "staging/In Progress", "color": "00cc00"}'


rm -rf _ObsPrj
rm -rf _ObsPrj-empty
rm -rf test-GitPkgA-change
rm -rf _ObsPrj-new-package


# create a project pull request without any package changes
git-obs repo fork pool/_ObsPrj
git-obs repo clone Admin/_ObsPrj --directory=_ObsPrj-empty --branch=factory
pushd _ObsPrj-empty
git branch empty
git switch empty
git commit -m empty-change --allow-empty
git push --set-upstream origin empty
git-obs pr create --title=empty --description='-' --target-branch=factory
popd


# create a package pull request
git-obs repo fork pool/test-GitPkgA
git-obs repo clone Admin/test-GitPkgA --directory=test-GitPkgA-change -b factory
pushd test-GitPkgA-change
git commit -m change1 --allow-empty
git push
git-obs pr create --title=test-GitPkgA-change --description='-'
popd

# create 2nd project pull request with a package change
git-obs repo clone Admin/_ObsPrj --directory=_ObsPrj-new-package
pushd _ObsPrj-new-package
git branch new-package
git switch new-package
git submodule add -b factory ../../pool/test-GitPkgA pkgs/test-GitPkgA
pushd pkgs/test-GitPkgA
git fetch origin pull/1/head:factory --force --update-head-ok
popd
git commit -m new-package --allow-empty -a
git push --set-upstream origin new-package
git-obs pr create --title=new-package --description='PR: pool/test-GitPkgA!1' --target-branch=factory
git-obs api -X POST /repos/pool/_ObsPrj/issues/2/labels --data='{"labels": ["staging/Backlog"]}'
popd

The commands I ran:

./git-obs.py staging merge pool/_ObsPrj#1 pool/_ObsPrj#2 --keep-temp-dir
./git-obs.py staging remove pool/_ObsPrj#1 'pool/test-GitPkgA!1' --keep-temp-dir


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

This assignment to 'pr_obj' is unnecessary as it is
redefined
before this value is used.

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.


Suggested changeset 1
osc/commands_git/staging_group.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/osc/commands_git/staging_group.py b/osc/commands_git/staging_group.py
--- a/osc/commands_git/staging_group.py
+++ b/osc/commands_git/staging_group.py
@@ -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}")
EOF
@@ -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}")
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +86 to +93
# 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

This comment appears to contain commented-out code.

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.


Suggested changeset 1
osc/commands_git/staging_group.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/osc/commands_git/staging_group.py b/osc/commands_git/staging_group.py
--- a/osc/commands_git/staging_group.py
+++ b/osc/commands_git/staging_group.py
@@ -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.")
EOF
@@ -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.")
Copilot is powered by AI and may make mistakes. Always verify output.
Comment on lines +106 to +113
# 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

This comment appears to contain commented-out code.

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.

Suggested changeset 1
osc/commands_git/staging_group.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/osc/commands_git/staging_group.py b/osc/commands_git/staging_group.py
--- a/osc/commands_git/staging_group.py
+++ b/osc/commands_git/staging_group.py
@@ -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.")
EOF
@@ -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.")
Copilot is powered by AI and may make mistakes. Always verify output.
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

Variable pr is not used.

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.

Suggested changeset 1
osc/commands_git/staging_remove.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/osc/commands_git/staging_remove.py b/osc/commands_git/staging_remove.py
--- a/osc/commands_git/staging_remove.py
+++ b/osc/commands_git/staging_remove.py
@@ -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)
 
EOF
@@ -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)

Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants