diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b78c99c..87a6931 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,8 +31,9 @@ jobs: pull-request-number: ${{ github.event.pull_request.number }} pull-request-body: ${{ github.event.pull_request.body }} copy-issues-labels: true # optional + include-closed-issues: true # optional - - name: Echo output + - name: Echo output in general run: | echo "is-pull-request-linked-to-issues: ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues }}" echo "linked-issues: ${{ steps.find-linked-issues.outputs.linked-issues }}" @@ -43,12 +44,14 @@ jobs: run: | echo "is-pull-request-linked-to-issues: ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues }}" echo "linked-issues: ${{ steps.find-linked-issues.outputs.linked-issues }}" + echo "pull-request-labels: ${{ steps.find-linked-issues.outputs.pull-request-labels }}" - name: Echo output when failure and exit if: ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues == 'False' }} run: | echo "is-pull-request-linked-to-issues: ${{ steps.find-linked-issues.outputs.is-pull-request-linked-to-issues }}" echo "linked-issues: ${{ steps.find-linked-issues.outputs.linked-issues }}" + echo "pull-request-labels: ${{ steps.find-linked-issues.outputs.pull-request-labels }}" exit 1 lint-workflow: diff --git a/README.md b/README.md index 3d746a7..c136604 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ You can also do this [manually](https://docs.github.com/en/issues/tracking-your- | `pull-request-number` | The pull request number to use. If pull requests are linked. | **required** | `${{ github.event.pull_request.number }}` | | `pull-request-body` | The pull request body to search for keywords like `Resolves #48`. | **required** | `${{ github.event.pull_request.body }}` | | `copy-issues-labels` | Copy the labels of the linked issues to the pull request. | optional | `false` | +| `include-closed-issues` | Includes closed issues, when searching for linked issues. | optional | `false` | | **Name OUTPUTS** | **Description** | **Values** | **Defaults** | | `is-pull-request-linked-to-issues` | Whether the pull request is linked to issues or not. | `'True'` or `'False'` | `'False'` | | `linked-issues` | List of issues that are linked to the pull request. | `[1, 2, 4, 82, 124]` | `[]` | @@ -37,6 +38,7 @@ Example workflow: pull-request-number: ${{ github.event.pull_request.number }} pull-request-body: ${{ github.event.pull_request.body }} copy-issues-labels: true # optional + include-closed-issues: true # optional # Use the output from the `find-linked-issues` step - name: Use the output diff --git a/action.yml b/action.yml index aa6cc9a..b390247 100644 --- a/action.yml +++ b/action.yml @@ -24,7 +24,11 @@ inputs: description: Copy the labels of the linked issues to the pull request. (optional) required: false default: 'false' - + include-closed-issues: + description: Includes closed issues, when searching for linked issues. (optional) + required: false + default: 'false' + outputs: is-pull-request-linked-to-issues: description: Whether the pull request is linked to issues or not. diff --git a/main.py b/main.py index 0db621a..7d56b1d 100644 --- a/main.py +++ b/main.py @@ -39,6 +39,16 @@ def main(): except KeyError: copy_issues_labels = False + try: + include_closed_issues = os.environ['INPUT_INCLUDE-CLOSED-ISSUES'] + except KeyError: + include_closed_issues = False + + if include_closed_issues: + is_open = "is:open" + else: + is_open = "" + print("Environment variables fetched successfully") """ Get pull request """ @@ -69,7 +79,7 @@ def main(): """ Find issues with GitHub API """ print("Fetching issues...") url = "https://api.github.com/search/issues?q=" \ - + f"repo:{repository} is:issue is:open linked:pr pr:{pull_request_number} " \ + + f"repo:{repository} is:issue {is_open} linked:pr pr:{pull_request_number} " \ + " ".join(str(i) for i in issue_numbers) print(f"Request url: {url}") headers = {