-
Notifications
You must be signed in to change notification settings - Fork 765
-
Hi a short question how would you undraft a pull request?
Tried with GHPullRequest.requestTeamReviewers but didn't work
Also tried with GHPullRequest.reopen() also not working.
Beta Was this translation helpful? Give feedback.
All reactions
Unfortunately, there's nothing you can do with the REST API, GitHub doesn't expose an endpoint for that (at least to my knowledge, I did another check and couldn't find something about it).
So what you need to do is use the GraphQL API which exposes a mutation for it: https://docs.github.com/en/graphql/reference/mutations#markpullrequestreadyforreview .
Some operations are only available in the REST API and some others are only available in the GraphQL API. That's a bit unfortunate but that's how it is.
I think I remember you asking questions in Quarkus GitHub App so if you are still using it, something like this should probably work (not tested):
Map<String, Object> variables = new HashM...Replies: 2 comments 10 replies
-
Unfortunately, there's nothing you can do with the REST API, GitHub doesn't expose an endpoint for that (at least to my knowledge, I did another check and couldn't find something about it).
So what you need to do is use the GraphQL API which exposes a mutation for it: https://docs.github.com/en/graphql/reference/mutations#markpullrequestreadyforreview .
Some operations are only available in the REST API and some others are only available in the GraphQL API. That's a bit unfortunate but that's how it is.
I think I remember you asking questions in Quarkus GitHub App so if you are still using it, something like this should probably work (not tested):
Map<String, Object> variables = new HashMap<>();
variables.put("pullRequestId", pullRequest.getNodeId());
Response response = gitHubGraphQLClient.executeSync("""
mutation MarkPullRequestReadyForReview($pullRequestId: ID!) {
markPullRequestReadyForReview(input: {
pullRequestId: $pullRequestId }) {
clientMutationId
}
}""", variables);
You have a full example here of how to use GraphQL in Quarkus GitHub App given Discussions are only exposed as GraphQL: https://github.com/quarkusio/quarkus-github-bot/blob/main/src/main/java/io/quarkus/bot/TriageDiscussion.java .
HTH.
Beta Was this translation helpful? Give feedback.
All reactions
-
I'll mark this as answer. Cause I think for PAT this should be the way to go. For Github Application's it's probably not possible.
Beta Was this translation helpful? Give feedback.
All reactions
-
I will have a closer look probably next week. Sometimes there are bugs on the GitHub side and they are not checking the right permission.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
The GitHub App can perform this operation, using the installation ID as the bearer token.
Query:
mutation MarkPullRequestReadyForReview {
markPullRequestReadyForReview(input: { pullRequestId: "<YOUR_PR_ID>" }) {
clientMutationId
}
}
(tested in Postman)
Beta Was this translation helpful? Give feedback.
All reactions
-
That is the GraphQL API, which this library doesn't support yet.
Beta Was this translation helpful? Give feedback.
All reactions
-
Yes I know, I was saying that this operation works with GH Apps as well, because @kanimaru was unsure if it was possible.
Beta Was this translation helpful? Give feedback.
All reactions
-
Almost work like that,
But now GitHub answers with:
GraphQLResponse{ data={"markPullRequestReadyForReview":null}, errors=[ Error{ message=Resource not accessible by integration, locations=[{line=2, column=3}], path=[markPullRequestReadyForReview], extensions={saml_failure=false}, otherFields={type=FORBIDDEN}} ] }
Code in Use:
graphql.executeAsync(""" mutation MarkPullRequestReadyForReview($pullRequestId: ID!) { markPullRequestReadyForReview(input: { pullRequestId: $pullRequestId }) { clientMutationId } } """, Map.of("pullRequestId", pullRequest.getNodeId())) .subscribe().with( response -> log.info("Undraft successfully: {}", response), throwable -> log.error("Can't undraft PR", throwable) );
The App has PR Read/Write, Issue Read/Write, Contents Read/Write access.
Any Idea whats missing?
Beta Was this translation helpful? Give feedback.
All reactions
-
I would expect PR Read/Write to be enough.
You use the GraphQL client automatically injected, right? Also common mistake: have you approved the permission changes if you have changed the permissions? You usually get an email to approve them if you change them after the creation.
Beta Was this translation helpful? Give feedback.
All reactions
-
Also the pull request is in a project where the GitHub App is installed?
Beta Was this translation helpful? Give feedback.
All reactions
-
I would expect PR Read/Write to be enough.
Yeah strange, maybe some special microsoft logic / bug
No there is no default bean to inject:
@Inject DynamicGraphQLClient graphql;
didn't work with: Caused by: java.lang.RuntimeException: URL not configured for client. Please define the property quarkus.smallrye-graphql-client.default.url or pass it to your client builder dynamically
Used:
@Produces @ApplicationScoped public DynamicGraphQLClient graphql(GitHubService gitHubService, GithubConfig config) { return gitHubService.getInstallationGraphQLClient(config.installationId()); }
to produce my own client.
And yes permissions are all approved.
And yes the Bot is in the same Organization and for this Repository enabled.
Beta Was this translation helpful? Give feedback.
All reactions
-
Are you doing that when listening to an event?
Because what you should do in this case is just add a DynamicGraphQLClient graphqlClient parameter to your method and it will be automatically injected and properly authenticated. But I suppose you would have a correct client the way you did it too even if not recommended.
All I can think of is maybe the installation id being incorrect.
Maybe try my way and see if it works better. See https://github.com/quarkusio/quarkus-github-bot/blob/main/src/main/java/io/quarkus/bot/TriageDiscussion.java#L41-L43 for an example.
Beta Was this translation helpful? Give feedback.
All reactions
-
The problem with the approach to get the client at the begin I would need to bubble it completly through the application through all layers until the end when the change will be executed. I tried you version also but same result. The installation id works for REST completely with creating PR answering etc. Just Undrafting doesn't work =,=....
But fine I give up and do it with labels instead. I think this Draft thing was just an: "Oh Gitlab has it. We need it to, please hack it in" thing...
Beta Was this translation helpful? Give feedback.