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 write to file #3

Merged
merged 3 commits into from
Apr 17, 2023
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ You can find all the inputs in [the action file](./action.yml) but let's walk th
- `noComments`: Boolean. If the action should only fetch Pull Requests that have 0 reviews (comments do not count).
- Short for `Ignore PRs that have comments`.
- **default**: false
- `fileOutput`: String. File to which the output from `data` should be written.
- Useful in the cases where the output is too big and GitHub Actions can not handle it as a variable.

#### Accessing other repositories

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ inputs:
required: false
description: If true, it will only collect PRs with NO reviews.
default: false
fileOutput:
required: false
description: File to which the output data should be written.
outputs:
repo:
description: 'The name of the repo in owner/repo pattern'
Expand All @@ -34,4 +37,4 @@ outputs:

runs:
using: 'docker'
image: 'docker://ghcr.io/paritytech/stale-pr-finder/action:0.0.1'
image: 'docker://ghcr.io/paritytech/stale-pr-finder/action:0.0.2'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stale-pr-finder",
"version": "0.0.1",
"version": "0.0.2",
"description": "GitHub action that finds stale PRs and produce an output with them",
"main": "src/index.ts",
"scripts": {
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { debug, getBooleanInput, getInput, info, setOutput, summary } from "@actions/core";
import { debug, getBooleanInput, getInput, info, setFailed, setOutput, summary } from "@actions/core";
import { context } from "@actions/github";
import { Context } from "@actions/github/lib/context";
import { github } from "@eng-automation/integrations";
import { writeFile } from "fs";
import moment from "moment";
import { byNoReviews, olderThanDays } from "./filters";
import { getPullRequestWithReviews } from "./githubApi";
Expand Down Expand Up @@ -72,6 +73,7 @@ const runAction = async (ctx: Context) => {
const inputDays = Number.parseInt(getInput("days-stale", { required: false }));
const daysStale = isNaN(inputDays) ? 5 : inputDays;
const stale = isNaN(daysStale);
const outputFile = getInput("fileOutput", { required: false });
console.log("daysStale", daysStale, stale);

const octokit = await github.getInstance({ authType: "token", authToken: token })
Expand Down Expand Up @@ -103,6 +105,14 @@ const runAction = async (ctx: Context) => {
const message = generateMarkdownMessage(filterReviews, repo);
setOutput("message", message);

if (outputFile) {
writeFile(outputFile, jsonData, err => {
if (err) {
setFailed(err);
}
})
}

await summary.addHeading(`${repo.owner}/${repo.repo}`)
.addHeading(`${amountOfStalePrs} stale PRs`, 3)
.addTable([
Expand Down