generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from gentlementlegen/fix/issue-closed-skip
fix: issue closed as non-planned is now skipped
- Loading branch information
Showing
5 changed files
with
88 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ca12c26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JUnit
Coverage Report (78%)