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

Added ability to pass in an optional PR number as a parameter #349

Merged

Conversation

credfeto
Copy link
Contributor

@credfeto credfeto commented Apr 19, 2022

So so it can be used in a workflow that creates a PR automatically like repo-sync/pull-request then add in labels at creation rather than having to run an additional workflow

name: Auto PR Creation
on:
  push:
    branches-ignore:
    - master
    - main

jobs:
  create-pull-request:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 1
        token: ${{ secrets.GITHUB_TOKEN }}
    - run: |
        echo COMMIT_MSG=`git log -1 --pretty=%B` >> $GITHUB_ENV

    - id: open-pr
      uses: repo-sync/pull-request@v2.6
      with:
        source_branch: ""                     # If blank, default: triggered branch
        destination_branch: "main"            # If blank, default: master
        pr_assignee: "${{ github.actor }}"    # Comma-separated list (no spaces)
        pr_label: "auto-pr"                   # Comma-separated list (no spaces)
        pr_draft: true                        # Creates pull request as draft
        pr_title: "${{ env.COMMIT_MSG }}"
        pr_body: "${{ steps.pr-template.outputs.content }}"
        github_token: ${{ secrets.GITHUB_TOKEN }}

    - name: Details
      run: |
          echo "URL: ${{steps.open-pr.outputs.pr_url}}"
          echo "PR: ${{steps.open-pr.outputs.pr_number}}"
          echo "CF: ${{steps.open-pr.outputs.has_changed_files}}"

    - uses: credfeto/labeler@feature/pass-in-pull-request-or-issue
      with:
        repo-token: "${{ secrets.GITHUB_TOKEN }}"
        configuration-path: .github/labeler.yml
        sync-labels: true
        pr-number: ${{steps.open-pr.outputs.pr_number}}

Also would fix #304

@credfeto credfeto requested a review from a team as a code owner April 19, 2022 23:10
@AndreiLobanovich AndreiLobanovich self-assigned this Jun 14, 2023
@AndreiLobanovich
Copy link
Contributor

Hello, @credfeto!

First of all, I want to thank you for the time and effort you've put into creating this pull request. We greatly appreciate contributions from our community and we recognize the value they bring to the continual improvement of our project.

Regarding your changes, I appreciate your insights and your attempt to refine the workings of the labeler action. However, it's worth noting that in the current setup, any PR created triggers the pull_request_target event. So any PR created gets labeled.

As for the issue you have mentioned, the proper way to label pull requests which were created before adding the labeler workflow would be pulling changes from the main branch (the newly added workflow) to your branch - that will trigger the pull_request_target event as well.

If I have missed any other use cases, feel free to propose them for consideration.

Best regards.

@credfeto
Copy link
Contributor Author

@AndreiLobanovich, my use case is slightly different - I've got a github action that creates a PR - which uses the github.token to create a PR as its trying to pick up branches that have been left dormant and not merged and make them visible so some sort of action can occur (e.g. continue work, merge, delete branch). as I can't impersonate whoever has worked on that branch, I've used the github token to create the PR. This wasn't triggering other workflows. If I used my user then due to policies prohibiting admin merge in some of the repos its used in, I wouldn't be able to merge any of the PRs that it created e.g:

      - id: open-pr
        uses: repo-sync/pull-request@v2.12
        with:
          source_branch: ""                     # If blank, default: triggered branch
          destination_branch: "main"            # If blank, default: master
          pr_assignee: ${{github.actor}}      # Comma-separated list (no spaces)
          pr_label: "auto-pr"                   # Comma-separated list (no spaces)
          pr_draft: ${{env.CREATE_DRAFT}}                        # Creates pull request as draft
          pr_title: ${{env.COMMIT_MSG}}
          pr_body: ${{steps.pr-template.outputs.content}}
          github_token: ${{github.token}}
          
     ## using forked verson of actions/labeler to get the pr_number that was created to add labels
      - uses: credfeto/labeler@feature/pass-in-pull-request-or-issue
        with:
          repo-token: ${{secrets.SOURCE_PUSH_TOKEN}}
          configuration-path: .github/labeler.yml
          sync-labels: true
          pr-number: ${{steps.open-pr.outputs.pr_number}}

Full workflow

@AndreiLobanovich
Copy link
Contributor

Hey, @credfeto, I have tested your implementation, it works well. Also, we have a feature request for labeling multiple pull request with a single run. We think that making this input able to accept not only a single pr number but also a list of pr numbers is a way to go. Could you implement this functionality?
The input should accept pr numbers in the following manner:

pr-number: |
  prnumber1
  prnumber2
  prnumber3
  etc

Additionally, please, consider adding checks for the input data.

@credfeto
Copy link
Contributor Author

@AndreiLobanovich, thanks.

I'll take a look at adding the multiple PRs and the validation. WRT the validation how far should i go - e.g - is it enough to check that its a valid positive number, or should it validate that it is an [open?] PR or issue?

@AndreiLobanovich
Copy link
Contributor

@credfeto I think we should check the input if it's a positive number and try to get the PR. If retrieval fails there should be a core.warning to notify the user that there is no such PR.

@credfeto credfeto force-pushed the feature/pass-in-pull-request-or-issue branch from 234b29b to 8800c89 Compare June 22, 2023 17:24
@credfeto credfeto requested a review from a team as a code owner June 22, 2023 17:24
@credfeto credfeto marked this pull request as draft June 22, 2023 17:25
Copy link
Contributor

@AndreiLobanovich AndreiLobanovich left a comment

Choose a reason for hiding this comment

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

Thanks for your effort! Just a few minor changes needed.

src/labeler.ts Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@MaksimZhukov
Copy link
Contributor

Hello @credfeto!
I would like to inquire about your progress, do you need any help from our side?

@credfeto
Copy link
Contributor Author

credfeto commented Jul 3, 2023

Hello @credfeto! I would like to inquire about your progress, do you need any help from our side?

All's fine - I've just been busy the last couple of weeks - just need to pick things up again fix up the issues reported. Hopefully will get that done today or tomorrow

@credfeto credfeto force-pushed the feature/pass-in-pull-request-or-issue branch from 8800c89 to 13ad946 Compare July 3, 2023 15:01
@credfeto credfeto marked this pull request as ready for review July 3, 2023 16:37
@credfeto
Copy link
Contributor Author

credfeto commented Jul 5, 2023

I think I've addressed all your comments above; let me know if there's anything I've missed

@credfeto
Copy link
Contributor Author

credfeto commented Jul 6, 2023

@MaksimZhukov Fixed the tests - had to revert one of the suggested fixes to get it to work

README.md Outdated Show resolved Hide resolved
src/labeler.ts Outdated Show resolved Hide resolved
__tests__/main.test.ts Outdated Show resolved Hide resolved
credfeto and others added 3 commits July 6, 2023 13:57
Co-authored-by: MaksimZhukov <46996400+MaksimZhukov@users.noreply.github.com>
Co-authored-by: MaksimZhukov <46996400+MaksimZhukov@users.noreply.github.com>
@MaksimZhukov MaksimZhukov dismissed AndreiLobanovich’s stale review July 6, 2023 15:10

The comments were resolved

@MaksimZhukov MaksimZhukov merged commit 327d35f into actions:main Jul 6, 2023
7 checks passed
@MaksimZhukov
Copy link
Contributor

Thank you @credfeto for the contribution!

@AndreiLobanovich AndreiLobanovich removed their request for review July 6, 2023 15:45
github-merge-queue bot pushed a commit to owntracks/android that referenced this pull request Jul 11, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/labeler](https://togithub.com/actions/labeler) | action |
minor | `v4.2.0` -> `v4.3.0` |

---

### ⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the logs
for more information.

---

### Release Notes

<details>
<summary>actions/labeler (actions/labeler)</summary>

### [`v4.3.0`](https://togithub.com/actions/labeler/releases/tag/v4.3.0)

[Compare
Source](https://togithub.com/actions/labeler/compare/v4.2.0...v4.3.0)

#### What's Changed

In scope of this release, the ability to specify pull request number(s)
was added by [@&#8203;credfeto](https://togithub.com/credfeto) in
[actions/labeler#349.

Support for reading from the configuration file presented on the runner
was added by [@&#8203;lrstanley](https://togithub.com/lrstanley) in
[actions/labeler#394.
It allows you to use a configuration file generated during workflow run
or uploaded from a separate repository.

Please refer to the [action
documentation](https://togithub.com/actions/labeler#inputs) for more
information.

This release also includes the following changes:

- Improved Error message for missing config file by
[@&#8203;Gornoka](https://togithub.com/Gornoka) in
[actions/labeler#475
- Early exit when no files are changed by
[@&#8203;nathanhammond](https://togithub.com/nathanhammond) in
[actions/labeler#456
- Add examples to match all repo files by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#600
- Fix a typo in the example about using the action outputs by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#606
- Bump eslint from 8.43.0 to 8.44.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#601
- Bump
[@&#8203;typescript-eslint/parser](https://togithub.com/typescript-eslint/parser)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#602
- Bump
[@&#8203;typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#604
- Bump tough-cookie from 4.1.2 to 4.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#609
- Bump
[@&#8203;octokit/plugin-retry](https://togithub.com/octokit/plugin-retry)
from 5.0.4 to 5.0.5 by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#610

#### New Contributors

- [@&#8203;credfeto](https://togithub.com/credfeto) made their first
contribution in
[actions/labeler#349
- [@&#8203;lrstanley](https://togithub.com/lrstanley) made their first
contribution in
[actions/labeler#394
- [@&#8203;nathanhammond](https://togithub.com/nathanhammond) made their
first contribution in
[actions/labeler#456

**Full Changelog**:
actions/labeler@v4...v4.3.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/owntracks/android).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41LjMiLCJ1cGRhdGVkSW5WZXIiOiIzNi41LjMiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
github-merge-queue bot pushed a commit to owntracks/android that referenced this pull request Jul 11, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/labeler](https://togithub.com/actions/labeler) | action |
minor | `v4.2.0` -> `v4.3.0` |

---

### ⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the logs
for more information.

---

### Release Notes

<details>
<summary>actions/labeler (actions/labeler)</summary>

### [`v4.3.0`](https://togithub.com/actions/labeler/releases/tag/v4.3.0)

[Compare
Source](https://togithub.com/actions/labeler/compare/v4.2.0...v4.3.0)

#### What's Changed

In scope of this release, the ability to specify pull request number(s)
was added by [@&#8203;credfeto](https://togithub.com/credfeto) in
[actions/labeler#349.

Support for reading from the configuration file presented on the runner
was added by [@&#8203;lrstanley](https://togithub.com/lrstanley) in
[actions/labeler#394.
It allows you to use a configuration file generated during workflow run
or uploaded from a separate repository.

Please refer to the [action
documentation](https://togithub.com/actions/labeler#inputs) for more
information.

This release also includes the following changes:

- Improved Error message for missing config file by
[@&#8203;Gornoka](https://togithub.com/Gornoka) in
[actions/labeler#475
- Early exit when no files are changed by
[@&#8203;nathanhammond](https://togithub.com/nathanhammond) in
[actions/labeler#456
- Add examples to match all repo files by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#600
- Fix a typo in the example about using the action outputs by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#606
- Bump eslint from 8.43.0 to 8.44.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#601
- Bump
[@&#8203;typescript-eslint/parser](https://togithub.com/typescript-eslint/parser)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#602
- Bump
[@&#8203;typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#604
- Bump tough-cookie from 4.1.2 to 4.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#609
- Bump
[@&#8203;octokit/plugin-retry](https://togithub.com/octokit/plugin-retry)
from 5.0.4 to 5.0.5 by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#610

#### New Contributors

- [@&#8203;credfeto](https://togithub.com/credfeto) made their first
contribution in
[actions/labeler#349
- [@&#8203;lrstanley](https://togithub.com/lrstanley) made their first
contribution in
[actions/labeler#394
- [@&#8203;nathanhammond](https://togithub.com/nathanhammond) made their
first contribution in
[actions/labeler#456

**Full Changelog**:
actions/labeler@v4...v4.3.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/owntracks/android).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41LjMiLCJ1cGRhdGVkSW5WZXIiOiIzNi41LjMiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
flookapa pushed a commit to flookapa/owntracks_android that referenced this pull request Aug 27, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/labeler](https://togithub.com/actions/labeler) | action |
minor | `v4.2.0` -> `v4.3.0` |

---

### ⚠ Dependency Lookup Warnings ⚠

Warnings were logged while processing this repo. Please check the logs
for more information.

---

### Release Notes

<details>
<summary>actions/labeler (actions/labeler)</summary>

### [`v4.3.0`](https://togithub.com/actions/labeler/releases/tag/v4.3.0)

[Compare
Source](https://togithub.com/actions/labeler/compare/v4.2.0...v4.3.0)

#### What's Changed

In scope of this release, the ability to specify pull request number(s)
was added by [@&#8203;credfeto](https://togithub.com/credfeto) in
[actions/labeler#349.

Support for reading from the configuration file presented on the runner
was added by [@&#8203;lrstanley](https://togithub.com/lrstanley) in
[actions/labeler#394.
It allows you to use a configuration file generated during workflow run
or uploaded from a separate repository.

Please refer to the [action
documentation](https://togithub.com/actions/labeler#inputs) for more
information.

This release also includes the following changes:

- Improved Error message for missing config file by
[@&#8203;Gornoka](https://togithub.com/Gornoka) in
[actions/labeler#475
- Early exit when no files are changed by
[@&#8203;nathanhammond](https://togithub.com/nathanhammond) in
[actions/labeler#456
- Add examples to match all repo files by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#600
- Fix a typo in the example about using the action outputs by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#606
- Bump eslint from 8.43.0 to 8.44.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#601
- Bump
[@&#8203;typescript-eslint/parser](https://togithub.com/typescript-eslint/parser)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#602
- Bump
[@&#8203;typescript-eslint/eslint-plugin](https://togithub.com/typescript-eslint/eslint-plugin)
from 5.60.1 to 5.61.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#604
- Bump tough-cookie from 4.1.2 to 4.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[actions/labeler#609
- Bump
[@&#8203;octokit/plugin-retry](https://togithub.com/octokit/plugin-retry)
from 5.0.4 to 5.0.5 by
[@&#8203;MaksimZhukov](https://togithub.com/MaksimZhukov) in
[actions/labeler#610

#### New Contributors

- [@&#8203;credfeto](https://togithub.com/credfeto) made their first
contribution in
[actions/labeler#349
- [@&#8203;lrstanley](https://togithub.com/lrstanley) made their first
contribution in
[actions/labeler#394
- [@&#8203;nathanhammond](https://togithub.com/nathanhammond) made their
first contribution in
[actions/labeler#456

**Full Changelog**:
actions/labeler@v4...v4.3.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/owntracks/android).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41LjMiLCJ1cGRhdGVkSW5WZXIiOiIzNi41LjMiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

Label previous PRs
6 participants