From 3d2aed65e037e1b91cc9705e36aba0196eba282c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 8 Dec 2021 19:15:52 +0000 Subject: [PATCH] feat: build for release --- README.md | 68 +++++++++++++++--------- bundle/index.js | 94 ++++++++++++++++++++++++--------- node_modules/.package-lock.json | 2 +- 3 files changed, 113 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 0eee670..56c6302 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,57 @@ # Find Last Issue -GitHub Action to find and export the number of last updated issue that has given labels. +GitHub Action to find and output the number of last updated issue that has given labels and state. -### Inputs +### Action inputs -#### `labels` +| Name | Description | Default | +| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | +| **\*** `labels` | Comma or newline-separated list of labels that the issue must have | +| `state` | Issue state. Can be one of the following strings: | `"open"` | -> required +### Action outputs -Comma-separated label names that the issue must have. +| 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. | -### Outputs +### Environment variables -#### `issue_number` - -The number of the issue found, if any. - -#### `has_found` - -Response status. Will be `true` if some issue was found. `false` otherwise. +| Name | Description | Default | +| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | +| `GITHUB_TOKEN` | `GITHUB_TOKEN` or a `repo` scoped [Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) | `GITHUB_TOKEN` secret created by GitHub | ## Example usage -```yaml -uses: micalevisk/find-last-issue -with: - labels: 'report,automated issue' -env: - ## Optional since it uses the `GITHUB_TOKEN` by default - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -``` - -For third-party repositories, you can use the `GITHUB_REPOSITORY` environment variable: +You can use this action along with [create-issue-from-file](https://github.com/peter-evans/create-issue-from-file) action, like: ```yaml -env: - GITHUB_REPOSITORY: owner/repo_name +# ... + +- name: Find the last open report issue + id: last_issue + uses: micalevisk/find-last-issue@v1 + with: + state: open + ## The issue must have the following labels + labels: | + report + automated issue + env: + ## Optional since it uses the `GITHUB_TOKEN` created by GitHub by default + 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' }} + uses: peter-evans/create-issue-from-file@v3 + with: + title: Foo + content-filepath: README.md + issue-number: ${{ steps.last_issue.outputs.issue_number }} + labels: | + report + automated issue ``` diff --git a/bundle/index.js b/bundle/index.js index 0aa159a..290041a 100644 --- a/bundle/index.js +++ b/bundle/index.js @@ -8275,30 +8275,30 @@ exports.octokit = new rest_1.Octokit({ debug: core.debug, info: core.info, warn: core.warning, - error: core.error + error: core.error, }, }); /***/ }), -/***/ 5290: +/***/ 416: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.findLastIssueWithLabels = void 0; +exports.findLastIssueWith = void 0; const client_js_1 = __nccwpck_require__(9368); const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/'); -async function findLastIssueWithLabels(labels) { - const { data: [lastIssueFound] } = await client_js_1.octokit.request('GET /repos/{owner}/{repo}/issues', { +async function findLastIssueWith(labels, state) { + const { data: [lastIssueFound], } = await client_js_1.octokit.request('GET /repos/{owner}/{repo}/issues', { headers: { accept: 'application/vnd.github.v3+json', }, owner, repo, - state: 'open', + state, labels: labels.join(','), sort: 'updated', direction: 'desc', @@ -8307,7 +8307,7 @@ async function findLastIssueWithLabels(labels) { }); return lastIssueFound; } -exports.findLastIssueWithLabels = findLastIssueWithLabels; +exports.findLastIssueWith = findLastIssueWith; /***/ }), @@ -8337,31 +8337,75 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", ({ value: true })); -const core = __importStar(__nccwpck_require__(2186)); -const find_last_issue_with_labels_1 = __nccwpck_require__(5290); +const utils = __importStar(__nccwpck_require__(6883)); +const core_1 = __nccwpck_require__(416); async function main() { - try { - const labels = core.getInput('labels', { required: true, trimWhitespace: true }).split(','); - const latestReportIssue = await (0, find_last_issue_with_labels_1.findLastIssueWithLabels)(labels); - let hasFoundSome = false; - if (latestReportIssue) { - hasFoundSome = true; - core.setOutput('issue_number', latestReportIssue.number); - } - core.setOutput('has_found', hasFoundSome); - } - catch (err) { - if (err instanceof Error) { - core.error(err.message); - } - core.setFailed('Something went wrong!'); + const inputs = { + labels: utils.getInputAsArray('labels', { required: true, trimWhitespace: true }), + state: utils.getInput('state', { required: false, trimWhitespace: true }) || 'open', + }; + const latestReportIssue = await (0, core_1.findLastIssueWith)(inputs.labels, inputs.state); + let hasFoundSome = false; + if (latestReportIssue) { + hasFoundSome = true; + utils.setOutput('issue_number', latestReportIssue.number); } + utils.setOutput('has_found', hasFoundSome); } if (require.main === require.cache[eval('__filename')]) { - main(); + main().catch((err) => { + if (err instanceof Error) { + utils.error(err.message); + } + utils.setFailed('Something went wrong!'); + }); } +/***/ }), + +/***/ 6883: +/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) { + +"use strict"; + +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.setOutput = exports.getInput = exports.getInputAsArray = exports.error = exports.setFailed = void 0; +const core = __importStar(__nccwpck_require__(2186)); +var core_1 = __nccwpck_require__(2186); +Object.defineProperty(exports, "setFailed", ({ enumerable: true, get: function () { return core_1.setFailed; } })); +Object.defineProperty(exports, "error", ({ enumerable: true, get: function () { return core_1.error; } })); +const getInputAsArray = (name, options) => core + .getInput(name, options) + .split(/[\n,]+/) + .map((value) => value.trim()) + .filter((val) => val !== ''); +exports.getInputAsArray = getInputAsArray; +const getInput = (name, options) => core.getInput(name, options); +exports.getInput = getInput; +const setOutput = (name, value) => core.setOutput(name, value); +exports.setOutput = setOutput; + + /***/ }), /***/ 2020: diff --git a/node_modules/.package-lock.json b/node_modules/.package-lock.json index de62dcd..38a70e8 100644 --- a/node_modules/.package-lock.json +++ b/node_modules/.package-lock.json @@ -1,6 +1,6 @@ { "name": "last-issue-action", - "version": "1.0.4", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": {