-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: Adds option to comment on a commit instead of the PR * test: Testing this feature * feat: Allows multiple selections for the comment-on option * ci: Fix test for dependabot by using different artifact name
- Loading branch information
1 parent
9f92563
commit af7a719
Showing
10 changed files
with
290 additions
and
24 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
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
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,73 @@ | ||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; | ||
import * as core from "@actions/core"; | ||
import { getCommentOn, type CommentOn } from "./getCommentOn"; | ||
|
||
vi.mock("@actions/core"); | ||
|
||
describe("getCommentOn()", () => { | ||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("returns the default value ['pr'] if no valid values are provided", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("invalid1, invalid2"); | ||
|
||
const result = getCommentOn(); | ||
expect(result).toEqual(["pr"]); | ||
expect(core.warning).toHaveBeenCalledWith( | ||
'No valid options for comment-on found. Falling back to default value "pr".', | ||
); | ||
}); | ||
|
||
it("logs invalid values", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("pr, invalid, commit"); | ||
|
||
const result = getCommentOn(); | ||
expect(result).toEqual(["pr", "commit"]); | ||
expect(core.warning).toHaveBeenCalledWith( | ||
'Invalid options for comment-on: invalid. Valid options are "pr" and "commit".', | ||
); | ||
}); | ||
|
||
it("returns valid values correctly", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("pr, commit"); | ||
|
||
const result = getCommentOn(); | ||
expect(result).toEqual(["pr", "commit"]); | ||
expect(core.warning).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("trims whitespace from the input", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("pr, commit"); | ||
|
||
const result = getCommentOn(); | ||
|
||
expect(result).toEqual(["pr", "commit"]); | ||
|
||
expect(core.warning).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it("returns valid values and logs invalid values", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue( | ||
"pr, invalid, commit, anotherInvalid", | ||
); | ||
|
||
const result = getCommentOn(); | ||
expect(result).toEqual(["pr", "commit"]); | ||
expect(core.warning).toHaveBeenCalledWith( | ||
'Invalid options for comment-on: invalid, anotherInvalid. Valid options are "pr" and "commit".', | ||
); | ||
}); | ||
|
||
it("for value 'none', returns empty array", () => { | ||
vi.spyOn(core, "getInput").mockReturnValue("none"); | ||
|
||
const result = getCommentOn(); | ||
|
||
expect(result).toEqual([]); | ||
}); | ||
}); |
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,43 @@ | ||
import * as core from "@actions/core"; | ||
|
||
type CommentOn = "pr" | "commit" | "none"; | ||
|
||
function getCommentOn(): CommentOn[] { | ||
const commentOnInput = core.getInput("comment-on"); | ||
if (commentOnInput === "none") { | ||
return []; | ||
} | ||
|
||
const commentOnList = commentOnInput.split(",").map((item) => item.trim()); | ||
|
||
let validCommentOnValues: Array<CommentOn> = []; | ||
const invalidCommentOnValues: string[] = []; | ||
|
||
for (const value of commentOnList) { | ||
if (value === "pr" || value === "commit") { | ||
validCommentOnValues.push(value as CommentOn); | ||
} else { | ||
invalidCommentOnValues.push(value); | ||
} | ||
} | ||
|
||
if (validCommentOnValues.length === 0) { | ||
core.warning( | ||
`No valid options for comment-on found. Falling back to default value "pr".`, | ||
); | ||
validCommentOnValues = ["pr"]; | ||
return validCommentOnValues; | ||
} | ||
|
||
if (invalidCommentOnValues.length > 0) { | ||
core.warning( | ||
`Invalid options for comment-on: ${invalidCommentOnValues.join(", ")}. Valid options are "pr" and "commit".`, | ||
); | ||
} | ||
|
||
return validCommentOnValues; | ||
} | ||
|
||
export { getCommentOn }; | ||
|
||
export type { CommentOn }; |
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
Oops, something went wrong.