Skip to content

Commit

Permalink
Merge pull request #27 from gentlementlegen/fix/issue-closed-skip
Browse files Browse the repository at this point in the history
fix: issue closed as non-planned is now skipped
  • Loading branch information
gentlementlegen authored Jun 2, 2024
2 parents c1bc547 + db3d753 commit ca12c26
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 19 deletions.
20 changes: 2 additions & 18 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import * as core from "@actions/core";
import { IssueActivity } from "./issue-activity";
import program from "./parser/command-line";
import { Processor } from "./parser/processor";
import { parseGitHubUrl } from "./start";
import { run } from "./run";

async function main() {
if (program.eventName === "issues.closed") {
const issue = parseGitHubUrl(program.eventPayload.issue.html_url);
const activity = new IssueActivity(issue);
await activity.init();
const processor = new Processor();
await processor.run(activity);
return processor.dump();
} else {
console.warn(`${program.eventName} is not supported, skipping.`);
}
}

main()
run()
.then((result) => {
core?.setOutput("result", result);
})
Expand Down
31 changes: 31 additions & 0 deletions src/run.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { IssueActivity } from "./issue-activity";
import program from "./parser/command-line";
import { Processor } from "./parser/processor";
import { parseGitHubUrl } from "./start";
import { getOctokitInstance } from "./get-authentication-token.ts";

export async function run() {
const { eventPayload, eventName } = program;
if (eventName === "issues.closed") {
if (eventPayload.issue.state_reason !== "completed") {
const result = "# Issue was not closed as completed. Skipping.";
await getOctokitInstance().issues.createComment({
body: `\`\`\`text\n${result}\n\`\`\``,
repo: eventPayload.repository.name,
owner: eventPayload.repository.owner.login,
issue_number: eventPayload.issue.number,
});
return result;
}
const issue = parseGitHubUrl(eventPayload.issue.html_url);
const activity = new IssueActivity(issue);
await activity.init();
const processor = new Processor();
await processor.run(activity);
return processor.dump();
} else {
const result = `${eventName} is not supported, skipping.`;
console.warn(result);
return result;
}
}
3 changes: 3 additions & 0 deletions tests/__mocks__/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ export const handlers = [
const createdPermit = db.permits.create(data);
return HttpResponse.json(createdPermit);
}),
http.post("https://api.github.com/repos/:owner/:repo/issues/:id/comments", () => {
return HttpResponse.json({});
}),
];
41 changes: 41 additions & 0 deletions tests/action.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint @typescript-eslint/no-var-requires: 0 */
import "../src/parser/command-line";
import { run } from "../src/run";
import { server } from "./__mocks__/node.ts";

beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

jest.mock("../src/parser/command-line", () => {
const cfg = require("./__mocks__/results/valid-configuration.json");
const dotenv = require("dotenv");
dotenv.config();
return {
stateId: 1,
eventName: "issues.closed",
authToken: process.env.GITHUB_TOKEN,
ref: "",
eventPayload: {
issue: {
html_url: "https://github.com/ubiquibot/comment-incentives/issues/22",
number: 1,
state_reason: "not_planned",
},
repository: {
name: "conversation-rewards",
owner: {
login: "ubiquibot",
},
},
},
settings: JSON.stringify(cfg),
};
});

describe("Action tests", () => {
it("Should skip when the issue is closed without the completed status", async () => {
const result = await run();
expect(result).toEqual("# Issue was not closed as completed. Skipping.");
});
});
12 changes: 11 additions & 1 deletion tests/process.issue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ jest.mock("../src/parser/command-line", () => {
authToken: process.env.GITHUB_TOKEN,
ref: "",
eventPayload: {
issue: { html_url: "https://github.com/ubiquibot/comment-incentives/issues/22" },
issue: {
html_url: "https://github.com/ubiquibot/comment-incentives/issues/22",
number: 1,
state_reason: "completed",
},
repository: {
name: "conversation-rewards",
owner: {
login: "ubiquibot",
},
},
},
settings: JSON.stringify(cfg),
};
Expand Down

1 comment on commit ca12c26

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 78%
77.92% (360/462) 66.19% (139/210) 81.05% (77/95)

JUnit

Tests Skipped Failures Errors Time
23 0 💤 0 ❌ 0 🔥 7.467s ⏱️
Coverage Report (78%)
File% Stmts% Branch% Funcs% LinesUncovered Line #s
All files77.9266.1981.0578.12 
src75.928073.3377.88 
   get-authentication-token.ts100100100100 
   github-types.ts100100100100 
   index.ts251000256–10
   issue-activity.ts96.0781.811009646–47
   run.ts60751006023–29
   start.ts54.545057.146062–63, 100–118, 130
src/configuration83.335010082.6 
   comment-types.ts0000 
   config-reader.ts66.665010066.6612, 20–22
   constants.ts100100100100 
   content-evaluator-config.ts100100100100 
   data-purge-config.ts100100100100 
   formatting-evaluator-config.ts100100100100 
   github-comment-config.ts100100100100 
   incentives.ts100100100100 
   permit-generation-configuration.ts100100100100 
   user-extractor-config.ts100100100100 
src/data-collection83.3365.3810082.85 
   collect-linked-pulls.ts83.3365.3810082.8510, 19, 60–64
src/parser77.4364.1882.1477.14 
   content-evaluator-module.ts62.6845.4558.336023–24, 56–57, 75–112, 141–145
   data-purge-module.ts81.8190.910081.8115–16
   formatting-evaluator-module.ts92.56010092.374–75, 87
   github-comment-module.ts84.746510084.7439–50, 58–59, 68, 119
   permit-generation-module.ts6637.555.556650–51, 58–65, 107, 124–138, 144, 165–171, 178–179
   processor.ts91.6683.3310091.6634–35, 72
   user-extractor-module.ts7676.1983.337616–17, 34, 47, 49–50
src/types83.335010083.33 
   env-type.ts100100100100 
   payout.ts80501008018

Please sign in to comment.