8000 feat!: move all env. vars to action inputs & follow naming conventions by polarathene · Pull Request #6 · micalevisk/last-issue-action · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat!: move all env. vars to action inputs & follow naming conventions #6

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
## DISCLAIMER: This file is intended to be used in development only.
##

GITHUB_REPOSITORY=nestjs/awesome-nestjs
## The value of `repository` action input
INPUT_REPOSITORY=nestjs/awesome-nestjs
## Get this from https://github.com/settings/tokens/new?scopes=repo
GITHUB_TOKEN=

INPUT_TOKEN=
## The value of `labels` action input
INPUT_LABELS="report"
## The value of `state` action input
Expand Down
51 changes: 25 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ GitHub Action to find and output the number of last updated issue that has given

### Action inputs

| Name | Description | Default |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| **\*** `labels` | Comma or newline-separated list of labels that the issue must have |
| `state` | Issue state to filter by. Can be one of the following strings: <ul><li> <code>"open"</code>: if you want to look up for open issues only </li><li> <code>"closed"</code>: if you want to look up for closed issues only </li><li> <code>"all"</code>: if you want to look up for open or closed ones </li></ul> | `"open"` |
| Name | Description | Default |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- |
| **\*** `repository` | The target GitHub owner and name separated by slash. For example: `micalevisk/last-issue-action`. | `${{ github.repository }}` |
| **\*** `token` | A [`repo`][settings-create-scoped-token] scoped [Personal Access Token][docs-token-pat] with at least [`issues: read` permissions][docs-token-permissions]. | `${{ github.token }}` |
| **\*** `labels` | Comma or newline-separated list of labels that the issue must have | |
| `state` | Issue state to filter by. Can be one of the following strings: <ul><li> <code>"open"</code>: if you want to look up for open issues only </li><li> <code>"closed"</code>: if you want to look up for closed issues only </li><li> <code>"all"</code>: if you want to look up for open or closed ones </li></ul> | `"open"` |

[docs-token-pat]: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token
[docs-token-permissions]: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
[settings-create-scoped-token]: https://github.com/settings/tokens/new?scopes=repo:status,repo_deployment,public_repo

### Action outputs

| Name | Description |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `issue_number` | The number of the issue found, if any. |
| `has_found` | Response status. Will be `true` if some issue was found. `false` otherwise. |
| `is_closed` | Will be `true` if the found issue is closed. The you can use `issue_number` to open it again with [another GitHub Action](https://github.com/marketplace/actions). |
| Name | Description |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `issue-number` | The number of the issue found, otherwise empty. |
| `has-found` | Response status. Will be `true` if some issue was found, otherwise `false`. |
| `is-closed` | Will be `true` if the issue found is closed, otherwise `false`. Then you can use `issue-number` to open it again with [another GitHub Action](https://github.com/marketplace/actions). |

Note that none of the above will be defined if any error occurs (eg: fetching a repository that doesn't exists).

If `has_found` is `true`, then `issue_number` and `is_closed` will be defined as well.

### Environment variables

| Name | Description | Default |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| `GITHUB_TOKEN` | `GITHUB_TOKEN` or a [`repo`](https://github.com/settings/tokens/new?scopes=repo:status,repo_deployment,public_repo) scoped [Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) | - |
If `has-found` is `true`, then `issue-number` and `is-close 8000 d` will be defined as well.

## Example usage

Expand All @@ -35,27 +35,26 @@ You can use this action along with [create-issue-from-file](https://github.com/p
# ...

- name: Find the last open report issue
id: last_issue
uses: micalevisk/last-issue-action@v1.2
id: last-issue
uses: micalevisk/last-issue-action@v2
with:
state: open
## The issue must have the following labels
# Find the last updated open issue that has these labels:
labels: |
report
automated issue
env:
## Mandatory for private repositories. Note that you don't need to create the `GITHUB_TOKEN` secret in your side
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: echo ${{ steps.last_issue.outputs.issue_number }}

- name: Update last updated report issue
if: ${{ steps.last_issue.outputs.has_found == 'true' }}
if: ${{ steps.last-issue.outputs.has-found == 'true' }}
uses: peter-evans/create-issue-from-file@v4
with:
title: Foo
content-filepath: README.md
issue-number: ${{ steps.last_issue.outputs.issue_number }}
# Update an existing issue if one was found (issue-number),
# otherwise an empty value creates a new issue:
issue-number: ${{ steps.last-issue.outputs.issue-number }}
# Add a label(s) that `last-issue` can use to find this issue,
# and any other relevant labels for the issue itself:
labels: |
report
automated issue
Expand Down
18 changes: 12 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,25 @@ name: 'Find Last Issue'
author: 'Micael Levi L. C.'
description: 'GitHub Action to find and export the number of last updated issue whithin some repository that has given labels.'
inputs:
repository:
description: 'The target GitHub owner and name separated by slash. For example: `micalevisk/last-issue-action`.'
default: ${{ github.repository }}
token:
description: 'The GitHub token providing at least `issues: read` authorization to the repository.'
default: ${{ github.token }}
labels:
description: 'Comma-separated label names that the issue must have.'
required: true
state:
description: 'Issue state to filter by. Can be `"open"`, `"closed"` or `"all"`'
required: false
outputs:
issue_number:
description: 'The number of the issue found, if any.'
has_found:
description: 'Response status. Will be `true` if some issue was found. `false` otherwise.'
is_closed:
description: 'Will be `true` if the found issue is closed. `false` otherwise.'
issue-number:
description: 'The number of the issue found, otherwise empty.'
has-found:
description: 'Response status. Will be `true` if some issue was found, otherwise `false`.'
is-closed:
description: 'Will be `true` if the issue found is closed, otherwise `false`.'
runs:
using: 'node16'
main: 'bundle/index.js'
Expand Down
15 changes: 6 additions & 9 deletions src/fetch-last-issue-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import { makeOctokitClient } from './client';
import { findLastIssueWith } from './core';

interface IssueFilters {
labels: string[];
state: 'open' | 'closed' | 'all';
}

interface EnvData {
githubToken: string;
/** The target GitHub owner and name separated by slash. */
githubRepository: string;
/** Supported issue filters. */
labels: string[];
state: 'open' | 'closed' | 'all';
}

type Options = {
inputs: IssueFilters;
environment: EnvData;
};

6D40 interface IssueMetadata {
Expand All @@ -24,9 +21,9 @@ interface IssueMetadata {

type IssueInfo = { hasFound: false } | ({ hasFound: true } & IssueMetadata);

export async function fetchLastIssueInfo({ environment, inputs }: Options): Promise<IssueInfo> {
const octokitClient = makeOctokitClient(environment.githubToken);
const [owner, repo] = environment.githubRepository.split('/', 2);
export async function fetchLastIssueInfo({ inputs }: Options): Promise<IssueInfo> {
const octokitClient = makeOctokitClient(inputs.githubToken);
const [owner, repo] = inputs.githubRepository.split('/', 2);
const latestReportIssue = await findLastIssueWith(octokitClient, {
withLabels: inputs.labels,
withState: inputs.state,
Expand Down
8 changes: 0 additions & 8 deletions src/global.d.ts

This file was deleted.

12 changes: 5 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import { fetchLastIssueInfo } from './fetch-last-issue-info';
if (require.main === module) {
fetchLastIssueInfo({
inputs: {
githubRepository: utils.getInput('repository', { required: true }),
githubToken: utils.getInput('token', { required: process.env.NODE_ENV !== 'development' }),
labels: utils.getInputAsArray('labels', { required: true, trimWhitespace: true }),
state: utils.getInput('state', { required: false, trimWhitespace: true }) || 'open',
},
environment: {
githubToken: process.env.GITHUB_TOKEN,
githubRepository: process.env.GITHUB_REPOSITORY,
},
})
.then((outputData) => {
if (outputData.hasFound) {
utils.setOutput('issue_number', outputData.issueNumber);
utils.setOutput('is_closed', outputData.isClosed);
utils.setOutput('issue-number', outputData.issueNumber);
utils.setOutput('is-closed', outputData.isClosed);
}

utils.setOutput('has_found', outputData.hasFound);
utils.setOutput('has-found', outputData.hasFound);
})
.catch((err) => {
if (err instanceof Error) {
Expand Down
20 changes: 13 additions & 7 deletions src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
declare type ActionInputs = {
/** The GitHub token providing authorization to query issues for the repository. */
token: string;

/** The target GitHub owner and name separated by slash. */
repository: string;

/** Comma or newline-separated list of labels that the issue must have. */
labels: string[];

Expand All @@ -13,15 +19,15 @@ declare type ActionInputs = {
};

declare type ActionOutputs = {
/** The number of the issue found, if any. */
issue_number: number;
/** The number of the issue found, otherwise empty. */
['issue-number']: number;

/** Response status. Will be `true` if some issue was found. `false` otherwise. */
has_found: boolean;
/** Response status. Will be `true` if some issue was found, otherwise `false`. */
['has-found']: boolean;

/**
* Will be `true` if the found issue is closed. `false` otherwise.
* The you can use `issue_number` to open it again with [another GitHub Action](https://github.com/marketplace/actions).
* Will be `true` if the issue found is closed, otherwise `false`.
* Then you can use `issue-number` to open it again with [another GitHub Action](https://github.com/marketplace/actions).
*/
is_closed: boolean;
['is-closed']: boolean;
};
0