Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to "Ready to Review" / undraft pull request #1578

Answered by gsmet
kanimaru asked this question in Q&A
Discussion options

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.

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
5 replies
Comment options

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.

Comment options

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.

Comment options

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)

Comment options

That is the GraphQL API, which this library doesn't support yet.

Comment options

Yes I know, I was saying that this operation works with GH Apps as well, because @kanimaru was unsure if it was possible.

Answer selected by kanimaru
Comment options

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?

You must be logged in to vote
5 replies
Comment options

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.

Comment options

Also the pull request is in a project where the GitHub App is installed?

Comment options

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.

Comment options

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.

Comment options

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /