Skip to content

Propagate labels from the issue to the PR #2357

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

Merged
merged 8 commits into from
May 31, 2023
Merged

Conversation

svekars
Copy link
Contributor

@svekars svekars commented May 30, 2023

Add a GH action that propagates labels from the issue to PR. The issue must be tagged with the docathon label.

@netlify
Copy link

netlify bot commented May 30, 2023

Deploy Preview for pytorch-tutorials-preview ready!

Name Link
🔨 Latest commit 395f6dd
🔍 Latest deploy log https://app.netlify.com/sites/pytorch-tutorials-preview/deploys/64776b4c58d96200086c68ca
😎 Deploy Preview https://deploy-preview-2357--pytorch-tutorials-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

run: |
pip install requests
pip install PyGithub
- name: Run Python script
Copy link
Contributor

Choose a reason for hiding this comment

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

It's the same the previous step, remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved

pip install requests
pip install PyGithub
- name: Set up env var
run: echo "PR_NUMBER=$((${{ github.event.pull_request.number }}))" >> $GITHUB_ENV
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of a separate step for "Set up env var", you can pass the PR number like this:

https://github.com/pytorch/pytorch/blob/main/.github/workflows/check-labels.yml#L52


# get issue number from the PR body
if re.search(r'#\d{1,5}', pull_request_body):
issue_number = int(re.findall(r'#(\d{1,5})', pull_request_body)[0])
Copy link
Contributor

Choose a reason for hiding this comment

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

This is too brittle.
What if there is a text like "This is a follow-up of for my PR #12345", then repo.get_issue will fail.
Also I'm not sure pull_request_body returns "#12345" and not "https://github.com/pytorch/tutorials/issue/12345"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed separately, for this purpose, this solution will suffice.

issue_label_names = [label.name for label in issue_labels]
labels_to_add = [label for label in issue_label_names if label not in pull_request_labels]
if labels_to_add:
pull_request.set_labels(*labels_to_add)
Copy link
Contributor

Choose a reason for hiding this comment

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

Name set_labels implies it will delete existing labels, would't it? Can you please add a ref to the doc showing that it would not remove existing labels?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably need to use add_to_labels instead.

@svekars svekars merged commit 29d4d24 into main May 31, 2023
@svekars svekars deleted the add-label-sync-workflow branch May 31, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants