-
Notifications
You must be signed in to change notification settings - Fork 20
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
also resolve conversations when dismissing reviews #76
Conversation
Since this functionality requires additional permissions, I would suggest making it optional, enabled via a special action config parameter, and disabled by default. Not everyone needs it (for example, I don't). |
Sure, I'll try to do that. When the action config is on, but the query detects permission's missing, I'd turn that into a an error output and step failure then, right? I'll also address the pylint hints. |
I think I have addressed everything |
I did another set of test PRs with the updated action. |
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.
Great job! 👍 💯 🥇
run_action.py
Outdated
if response.status_code == 200: | ||
if "errors" in response.json(): | ||
msg = response.json()["errors"][0]["message"] | ||
if "Resource not accessible by integration" in msg: | ||
print( | ||
"::error::Closing conversations requires `contents: write` permission." | ||
) | ||
else: | ||
print(f"::error::Closing conversation query failed: {msg}") | ||
else: | ||
print("Conversation closed successfully.") | ||
return | ||
else: | ||
print(f"::error::GraphQL request failed: {response.status_code}") | ||
print( | ||
"::error:: Failed to close conversation. See log for details and " | ||
"https://github.com/platisd/clang-tidy-pr-comments/blob/master/README.md for help" | ||
) | ||
raise RuntimeError("Failed to close 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.
Can we please refactor this to decrease the "depth" of the function? E.g. it should look like this, with the opposite logic and multiple return statements. No nested if
s:
if response.status_code != 200:
print(f"::error::GraphQL request failed: {response.status_code}")
# ...
raise RuntimeError("Failed to close conversation.")
if "errors" not in response.json():
print("Conversation closed successfully.")
return
msg = response.json()["errors"][0]["message"]
# ....
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.
With the current flow we don't have to repeat the runtime error + print for the error cases in the response.status_code == 200
branch.
Do you want me to pull the print+raise into a local function, do the reorder and call that function where needed?
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 am OK with both the local function and also with this small duplication. 👍
"""Generator of unresolved conversation threads to close | ||
|
||
Uses the GitHub GraphQL API to get conversation threads for the given PR. | ||
Then filters for unresolved threads and those that have been created by the action. |
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.
Question: Where do we select those created by the action?
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.
Fair point. I guess we select open conversations started by the github-action user: https://github.com/platisd/clang-tidy-pr-comments/pull/76/files#diff-9981508c066d4bcb876bb89f7092ac196ce743485c2782d4142e6eb5e7c34457R561-R563
which might select conversations not actually started by the action. There's no message prefix to check for those though, right? Do you have another idea how to make the selection tighter?
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.
Maybe it's a good idea to exploit that every message starts with ⚠️ .... ⚠️
?
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.
Ah, yes. Maybe pull up that string to either module level "constant" or pass it around like the warning prefix? Just so the two places cannot drift?
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.
Sounds like a plan 👍
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.
done. Tried to be explicit with using the kw-arg version in existing code.
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.
Maybe it's enough with the single_comment_prefix
for now, but what about a regex that checks that the first line starts and finishes with :warning:
?
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.
Updated to use a regex
Co-authored-by: Dimitris Platis <platisd@users.noreply.github.com>
f533399
to
b831af1
Compare
Tried a new round of check PRs. Looks like I borked the comment-warning bit as it's no longer auto-closing in the test. Will revist later. |
454dea5
to
bdac58f
Compare
670e507
to
c7c8637
Compare
New round of PRs that check new beahviour: PR that only got the the change request closed |
@@ -28,4 +28,5 @@ cd "$recreated_repo_dir" | |||
--repository "$GITHUB_REPOSITORY" \ | |||
--repository-root "$recreated_repo_dir" \ | |||
--request-changes "$INPUT_REQUEST_CHANGES" \ | |||
--suggestions-per-comment "$INPUT_SUGGESTIONS_PER_COMMENT" | |||
--suggestions-per-comment "$INPUT_SUGGESTIONS_PER_COMMENT" \ | |||
--auto-resolve-conversations "$INPUT_AUTO_RESOLVE_CONVERSATIONS" \ |
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.
There's an extra backslash.
Resolving conversations is not available through the Rest API so we need to use the GraphQL one. This is the first time using it for me.
The mutation query needs the token to have
contents: write
. I found no documentation for this. Basically had to bisect the range of all possible perms to find that.I've made the missing permission not fail the action to allow a "soft" upgrade path. An annotation is added to the github actions run. Not sure if that's a good path, it's not super obvious where that message comes from. Could use a link back to actual README?
Example with full permission
Example with missing permission