-
Notifications
You must be signed in to change notification settings - Fork 33
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
Fix PR Metadata and Downstream issues #1466
Changes from 20 commits
fa795fb
431e962
b26a708
b9901d2
f8588cb
5ce64d2
d13549c
e2cc443
1211823
558efd0
1b21824
7367c57
153657b
c83cdd4
496a219
8409ab1
c4319d7
3ffaef2
f856451
18f6ed1
74e225a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Add Label | ||
|
||
## Inputs | ||
* `issue_number`: The issue number derived from the event payload. Default is `${{ github.event.number }}` then `${{ github.event.issue.number }}`. Action will fail if neither of these is present. If you need to use this action on a push event (or any event not associated directly with an `issue` or `pull_request`, please see [gh-find-current-pr](https://github.com/jwalton/gh-find-current-pr)) | ||
* `label`: The label to add to the issue | ||
|
||
|
||
## Usage: | ||
|
||
```yaml | ||
- name: Add Label | ||
uses: ./.github/actions/add-label | ||
with: | ||
label: 'needs-go-generate-${{matrix.package}}' | ||
issue-number: ${{github.event.number}} | ||
``` | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Add Label | ||
description: Add a label to the issue or pull request | ||
inputs: | ||
issue_number: | ||
description: 'The issue number to associate with. Defaults to the current issue or pull request number used to trigger the action.' | ||
required: false | ||
default: '' | ||
label: | ||
description: 'The label to add.' | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
# # TODO, dedupe w/ remove-label | ||
- name: Resolve issue number | ||
id: resolve_issue_number | ||
run: | | ||
if [[ -n '${{ inputs.issue_number }}' ]]; then | ||
echo 'Using input issue number: ${{ inputs.issue_number }}' | ||
echo '::set-output name=issue::${{ inputs.issue_number }}' | ||
elif [[ -n '${{ github.event.number }}' ]]; then | ||
echo 'Using event number: ${{ github.event.number }}' | ||
echo '::set-output name=issue::${{ github.event.number }}' | ||
elif [[ -n '${{ github.event.issue.number }}' ]]; then | ||
echo 'Using event issue number: ${{ github.event.issue.number }}' | ||
echo '::set-output name=issue::${{ github.event.issue.number }}' | ||
else | ||
echo 'Could not determine issue number' | ||
exit 1 | ||
fi | ||
shell: bash | ||
|
||
- name: Add Label | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
github.rest.issues.addLabels({ | ||
issue_number: ${{ steps.resolve_issue_number.outputs.issue }}, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ['${{ inputs.label }}'] | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Add Label | ||
|
||
## Inputs | ||
* `issue_number`: The issue number derived from the event payload. Default is `${{ github.event.number }}` then `${{ github.event.issue.number }}`. Action will fail if neither of these is present. If you need to use this action on a push event (or any event not associated directly with an `issue` or `pull_request`, please see [gh-find-current-pr](https://github.com/jwalton/gh-find-current-pr)) | ||
* `label`: The label to add to the issue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description of the - * `label`: The label to add to the issue
+ * `label`: The label to remove from the issue |
||
|
||
|
||
```yaml | ||
- name: Remove Label | ||
uses: ./.github/actions/remove-label | ||
with: | ||
label: 'needs-go-generate-${{matrix.package}}' | ||
issue-number: ${{github.event.number}} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Remove Label | ||
description: Remove a label to the issue or pull request | ||
inputs: | ||
issue_number: | ||
description: 'The issue number to associate with. Defaults to the current issue or pull request number used to trigger the action.' | ||
required: false | ||
default: '' | ||
label: | ||
description: 'The label to add.' | ||
required: true | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
# TODO, dedupe w/ add-label | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: Resolve issue number | ||
id: resolve_issue_number | ||
run: | | ||
if [[ -n '${{ inputs.issue_number }}' ]]; then | ||
echo 'Using input issue number: ${{ inputs.issue_number }}' | ||
echo '::set-output name=issue::${{ inputs.issue_number }}' | ||
elif [[ -n '${{ github.event.number }}' ]]; then | ||
echo 'Using event number: ${{ github.event.number }}' | ||
echo '::set-output name=issue::${{ github.event.number }}' | ||
elif [[ -n '${{ github.event.issue.number }}' ]]; then | ||
echo 'Using event issue number: ${{ github.event.issue.number }}' | ||
echo '::set-output name=issue::${{ github.event.issue.number }}' | ||
else | ||
echo 'Could not determine issue number' | ||
exit 1 | ||
fi | ||
Comment on lines
+15
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code for resolving the issue number is duplicated in - # TODO, dedupe w/ add-label
- - name: Resolve issue number
- id: resolve_issue_number
- run: |
- if [[ -n '${{ inputs.issue_number }}' ]]; then
- echo 'Using input issue number: ${{ inputs.issue_number }}'
- echo '::set-output name=issue::${{ inputs.issue_number }}'
- elif [[ -n '${{ github.event.number }}' ]]; then
- echo 'Using event number: ${{ github.event.number }}'
- echo '::set-output name=issue::${{ github.event.number }}'
- elif [[ -n '${{ github.event.issue.number }}' ]]; then
- echo 'Using event issue number: ${{ github.event.issue.number }}'
- echo '::set-output name=issue::${{ github.event.issue.number }}'
- else
- echo 'Could not determine issue number'
- exit 1
- fi
- shell: bash There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. already added a todo for this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @trajan0x, I understand that you've added a TODO comment to address this issue in the future. However, it's generally a good practice to avoid merging code that contains duplication, especially when the duplication is non-trivial and could be abstracted into a reusable component. This is in line with the DRY (Don't Repeat Yourself) principle, which is a fundamental concept in software development for reducing repetition of software patterns, replacing it with abstractions or using data normalization to avoid redundancy. Here's a suggestion on how you could abstract the issue number resolution logic into a separate GitHub action: name: Resolve Issue Number
description: Resolve the issue number from inputs or event context
inputs:
issue_number:
description: 'The issue number to associate with. Defaults to the current issue or pull request number used to trigger the action.'
required: false
default: ''
runs:
using: 'composite'
steps:
- name: Resolve issue number
id: resolve_issue_number
run: |
if [[ -n '${{ inputs.issue_number }}' ]]; then
echo 'Using input issue number: ${{ inputs.issue_number }}'
echo '::set-output name=issue::${{ inputs.issue_number }}'
elif [[ -n '${{ github.event.number }}' ]]; then
echo 'Using event number: ${{ github.event.number }}'
echo '::set-output name=issue::${{ github.event.number }}'
elif [[ -n '${{ github.event.issue.number }}' ]]; then
echo 'Using event issue number: ${{ github.event.issue.number }}'
echo '::set-output name=issue::${{ github.event.issue.number }}'
else
echo 'Could not determine issue number'
exit 1
fi
shell: bash
outputs:
issue:
description: 'The resolved issue number' Then, in your - name: Resolve Issue Number
id: resolve_issue_number
uses: ./.github/actions/resolve-issue-number
with:
issue_number: ${{ inputs.issue_number }} This way, you can keep your code DRY and maintainable. |
||
shell: bash | ||
|
||
- name: Remove Label | ||
uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
github.rest.issues.removeLabel({ | ||
issue_number: ${{ steps.resolve_issue_number.outputs.issue }}, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: ['${{ inputs.label }}'] | ||
}) | ||
trajan0x marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value for
issue_number
is first set to${{ github.event.number }}
and then${{ github.event.issue.number }}
. However, the action will fail if neither of these is present. This could be a potential issue if the action is used in a context where these values are not available. Consider adding error handling or a more descriptive failure message to guide users in such scenarios.