Skip to content

Commit

Permalink
Fixed filter order execution (#10)
Browse files Browse the repository at this point in the history
Fixed the moment where the results are filtered.

Before we assumed that if we had stale issues, that was a positive
result and then we would execute the filters.

With this change we execute filters BEFORE we take the happy path,
solving us from the issue of reporting 5 issues but not showing anything
in the data.

I also removed the summary from the event that there are no stale issues
as it was over population the summary page
  • Loading branch information
Bullrich committed Apr 4, 2023
1 parent 8fe440a commit dc1e870
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ outputs:

runs:
using: 'docker'
image: 'docker://ghcr.io/paritytech/stale-issues-finder/action:0.0.3'
image: 'docker://ghcr.io/paritytech/stale-issues-finder/action:0.0.4'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stale-issues-finder",
"version": "0.0.3",
"version": "0.0.4",
"description": "Find what issues have been stale for a given time",
"main": "src/index.ts",
"engines": {
Expand Down
24 changes: 16 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getBooleanInput, getInput, info, setOutput, summary } from "@actions/core";
import { debug, getBooleanInput, getInput, info, setOutput, summary } from "@actions/core";
import { context, getOctokit } from "@actions/github";
import { Context } from "@actions/github/lib/context";
import moment from "moment";
Expand Down Expand Up @@ -49,6 +49,10 @@ const getRepo = (ctx: Context): { owner: string, repo: string } => {
}

const filterIssues = (issues: IssueData[], filters: Filters) => {
if (!issues || issues.length < 1) {
return [];
}

let filteredData = issues;
if (filters.daysStale) {
filteredData = filteredData.filter(is => olderThanDays(is, filters.daysStale));
Expand All @@ -68,20 +72,22 @@ const runAction = async (ctx: Context) => {
const token = getInput("GITHUB_TOKEN", { required: true });

const filters = getFiltersFromInput();
debug(JSON.stringify(filters));

const octokit = getOctokit(token);
const staleIssues = await fetchIssues(octokit, repo);

const amountOfStaleIssues = staleIssues.length;
// we filter the issues and see how many are remaining
const filteredIssues = filterIssues(staleIssues, filters);

const amountOfStaleIssues = filteredIssues.length;

info(`Found ${amountOfStaleIssues} stale issues.`);
setOutput("repo", `${repo.owner}/${repo.repo}`);
setOutput("stale", amountOfStaleIssues);

if (amountOfStaleIssues > 0) {
const filteredData = filterIssues(staleIssues, filters);

let cleanedData = filteredData.map(issue => {
let cleanedData = filteredIssues.map(issue => {
return {
url: issue.html_url,
title: issue.title,
Expand All @@ -90,8 +96,10 @@ const runAction = async (ctx: Context) => {
}
});

setOutput("data", JSON.stringify(cleanedData));
const message = generateMarkdownMessage(staleIssues, repo);
const jsonData = JSON.stringify(cleanedData)
setOutput("data", jsonData);
debug(jsonData);
const message = generateMarkdownMessage(filteredIssues, repo);
setOutput("message", message);

await summary.addHeading(`${repo.owner}/${repo.repo}`)
Expand All @@ -103,7 +111,7 @@ const runAction = async (ctx: Context) => {
.addLink("See all issues", `https://github.com/${repo.owner}/${repo.repo}/issues`).write();
} else {
setOutput("message", `### Repo ${repo.owner}/${repo.repo} has no stale issues`);
await summary.addHeading(`${repo.owner}/${repo.repo}`).addHeading("No stale issues", 3).addEOL().write();
info(`Repo ${repo.owner}/${repo.repo} has no stale issues`);
}
}

Expand Down

0 comments on commit dc1e870

Please sign in to comment.