-
Notifications
You must be signed in to change notification settings - Fork 2k
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
tools/hydracomment: Add tool for simultaneous commenting #20001
Open
bergzand
wants to merge
1
commit into
RIOT-OS:master
Choose a base branch
from
bergzand:pr/dist/hydracomment
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Comment on multiple PRs | ||
============================= | ||
|
||
This script provides functionality to place the same comment simultaneously on | ||
multiple PRs | ||
|
||
It relies on having a `github` API token, stored in `~/.riotgithubtoken` by | ||
default. | ||
|
||
Usage | ||
----- | ||
|
||
Most common usage would be to run: | ||
|
||
hydracomment.py PR_NUMBER1 PR_NUMBER2 ... | ||
|
||
See the backport_pr README.md for instructions on creating a token with correct | ||
permissions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2023 Koen Zandberg | ||
# | ||
# This file is subject to the terms and conditions of the GNU Lesser | ||
# General Public License v2.1. See the file LICENSE in the top level | ||
# directory for more details. | ||
# | ||
# @author Koen Zandberg <[email protected]> | ||
|
||
""" | ||
Place identical comments on multiple PRs. | ||
Note that with great power comes great responsibility | ||
""" | ||
|
||
import os | ||
import sys | ||
import argparse | ||
from agithub.GitHub import GitHub | ||
|
||
ORG = "RIOT-OS" | ||
REPO = "RIOT" | ||
GITHUBTOKEN_FILE = ".riotgithubtoken" | ||
|
||
|
||
def main(): | ||
keyfile = os.path.join(os.environ["HOME"], GITHUBTOKEN_FILE) | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"-k", | ||
"--keyfile", | ||
type=argparse.FileType("r"), | ||
default=keyfile, | ||
help="File containing github token", | ||
) | ||
parser.add_argument( | ||
"-c", | ||
"--comment", | ||
default="Bors merge", | ||
type=str, | ||
help="Comment to place under all PRs.", | ||
) | ||
parser.add_argument( | ||
"PR", | ||
nargs='+', | ||
type=int, | ||
help="Pull request number to place comment on", | ||
) | ||
args = parser.parse_args() | ||
|
||
gittoken = args.keyfile.read().strip() | ||
github_api = GitHub(token=gittoken) | ||
|
||
status, user = github_api.user.get() | ||
if status != 200: | ||
print(f'Could not retrieve user: {user["message"]}') | ||
sys.exit(1) | ||
|
||
response_headers = dict(github_api.getheaders()) | ||
if "X-OAuth-Scopes" in response_headers: | ||
scopes = response_headers["X-OAuth-Scopes"] | ||
else: | ||
scopes = response_headers["x-oauth-scopes"] | ||
scopes_list = [x.strip() for x in scopes.split(",")] | ||
if not ("public_repo" in scopes_list or "repo" in scopes_list): | ||
print( | ||
"missing public_repo scope from token settings." | ||
" Please add it on the GitHub webinterface" | ||
) | ||
sys.exit(1) | ||
|
||
comment = {"body": args.comment} | ||
for prnum in args.PR: | ||
status, pulldata = github_api.repos[ORG][REPO].pulls[prnum].get() | ||
if status != 200: | ||
print(f'PR #{prnum} not found: {pulldata["message"]}') | ||
continue | ||
status, res = ( | ||
github_api.repos[ORG][REPO].issues[prnum].comments.post(body=comment) | ||
) | ||
if status != 201: | ||
print(f'Something went wrong adding the comment to #{prnum}: {res["message"]}') | ||
else: | ||
print(f"Added comment to #{prnum}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
agithub==2.2.2 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 if it is case sensitive, but so far we always used the lower case version.