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

Is it possible to create a pull request with a label? #1862

Closed
stt106 opened this issue Sep 3, 2018 · 7 comments
Closed

Is it possible to create a pull request with a label? #1862

stt106 opened this issue Sep 3, 2018 · 7 comments

Comments

@stt106
Copy link

stt106 commented Sep 3, 2018

We have some system watching pull requests with specific labels; hence I am wondering whether it's possible to pragmatically create a pull request and attach a label to it?

@ryangribble
Copy link
Contributor

ryangribble commented Sep 3, 2018

Yes it is - you need to have write access to the repository to apply the label though. You can use the issues API to set the label on the PR (PR's are also Issues, in API terms)

@stt106
Copy link
Author

stt106 commented Sep 4, 2018

@ryangribble thanks for the reply. Sorry but I am new to the package so not sure I fully understand you.
On the doc, I see I can add a label to a NewIssue like

var myNewIssue = new NewIssue("Issue with dropdown menu");
myNewIssue.Labels.Add("bug");

I am creating a pull request using

var github = new GitHubClient(new ProductHeaderValue(config.User), 
                                      new Uri("https://simhub.simcorp.com"),
                                      Credentials = Credentials(config.Password));
                                            
       var pr = github.PullRequest.Create("Foo", "Bar", 
            new NewPullRequest("PR title", branchName, "master"));

There is no Labels property on PullRequest hence unsure where/how to add the label to a pull request.

@ryangribble
Copy link
Contributor

In github API terms, a pull request is actually a special type of issue (you
may have noticed on github that the issue number and pull request number are shared/unique across issues and PR's! )

So you can actually use most of the issue API calls to do things to pull requests (get comments, set labels, milestones, assignees etc)

so once you create the PR you can use the IssueUpdate request to update it and set the label

@stt106
Copy link
Author

stt106 commented Sep 4, 2018

@ryangribble thanks again for the reply. Just to confirm that I understand you correctly. Once I have a PR e.g. pr, then I will do something like this:

var issueUpdate = new IssueUpdate();
issueUpdate.Labels.Add("some label");
// pass in pr.Number below
gitHub.Issue.Update("owner", "repo name", pr.Number, issueUpdate);

I guess the key is passing pr.Number as the issue number in the Update method?

@ryangribble
Copy link
Contributor

Yep! Let us know if you have any problems doing this

You can also see the official mention of this in the github docs here: https://developer.github.com/v3/pulls/#labels-assignees-and-milestones

@stt106 stt106 closed this as completed Sep 4, 2018
@niteshkhannaupstart
Copy link

owner

what does owner mean here? gitHub.Issue.Update("owner", "repo name", pr.Number, issueUpdate);

What value does it or it should hold?

@salvadorgonmo
Copy link

Is it possible to use issues to automatically assign a Project to a PR when it has an specific label?

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

No branches or pull requests

4 participants