pythonpython-3.xapigithubgithub3.py

How to put labels on new pull request using github3.py?


I saw that github3.py still doesn't have the attribute labels on Repository.create_pull() as in Repository.create_issue(). But there is the property labels on ShortPullRequest created. So I tried:

created_pr = repo.create_pull(
    title=pr.title,
    body=pr.body,
    head=pr.head,
    base=pr.base,
)
if pr.labels:
    created_pr.labels = pr.labels
    created_pr.update()

The problem is that after I check on GitHub, the PR was created with no labels. Is there any solution for this using this component?

Note: I can't use pygithub since they use LGPL Licence and I want to make MIT Licence code.


Solution

  • Actually, the way to do it is:

    if pr.labels:
        issue = created_pr.issue()
        issue.add_labels(*pr.labels)
    

    Thanks @sigmavirus24 on Github.