Skip to content
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

Merged
merged 14 commits into from
Mar 25, 2024

Conversation

renefritze
Copy link
Contributor

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

@oleg-derevenetz
Copy link
Contributor

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.

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).

@renefritze
Copy link
Contributor Author

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.

@renefritze
Copy link
Contributor Author

I think I have addressed everything

@renefritze
Copy link
Contributor Author

renefritze commented Mar 21, 2024

I did another set of test PRs with the updated action.
No auto resolving
Auto resolving
Auto resolving w/o setting the permission with failure

Copy link
Owner

@platisd platisd left a 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 Show resolved Hide resolved
run_action.py Show resolved Hide resolved
run_action.py Outdated
Comment on lines 597 to 615
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.")
Copy link
Owner

@platisd platisd Mar 21, 2024

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 ifs:

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"]
# ....

Copy link
Contributor Author

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?

Copy link
Owner

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. 👍

run_action.py Outdated Show resolved Hide resolved
"""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.
Copy link
Owner

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?

Copy link
Contributor Author

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?

Copy link
Owner

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 ⚠️ .... ⚠️?

Copy link
Contributor Author

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?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a plan 👍

Copy link
Contributor Author

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.

Copy link
Owner

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:?

Copy link
Contributor Author

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

renefritze and others added 3 commits March 22, 2024 09:00
@renefritze
Copy link
Contributor Author

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.

@renefritze
Copy link
Contributor Author

New round of PRs that check new beahviour:

PR that only got the the change request closed
PR with right perms that got conversation closed
PR with auto-close enabled, but perms missing

@platisd platisd merged commit 837ad80 into platisd:master Mar 25, 2024
3 checks passed
@@ -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" \
Copy link
Contributor

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.

@renefritze renefritze deleted the resolve_conversations branch March 26, 2024 07:41
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