forked from ffittschen/pr-branch-labeler
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #9 from TheCleric/feature/enhance-debugging
Added enhanced debugging and the ability to use changes to the config file within the PR itself
- Loading branch information
Showing
15 changed files
with
306 additions
and
4,056 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 |
---|---|---|
|
@@ -123,3 +123,6 @@ Temporary Items | |
.apdisk | ||
|
||
# End of https://www.gitignore.io/api/macos | ||
|
||
lib/src | ||
lib/__tests__ |
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,95 @@ | ||
import * as github from "@actions/github"; | ||
import * as Context from '@actions/github/lib/context'; | ||
import "jest-extended"; | ||
import nock from "nock"; | ||
import path from "path"; | ||
import { getConfig } from '../src/config'; | ||
import { configFixture, emptyConfigFixture } from './shared'; | ||
|
||
|
||
nock.disableNetConnect(); | ||
|
||
describe("Config file loader", () => { | ||
let context; | ||
|
||
beforeEach(() => { | ||
const repoToken = "token"; | ||
process.env["INPUT_REPO-TOKEN"] = repoToken; | ||
process.env["GITHUB_REPOSITORY"] = "Codertocat/Hello-World"; | ||
process.env["GITHUB_EVENT_PATH"] = path.join(__dirname, "fixtures", "payload.json"); | ||
|
||
context = new Context.Context(); | ||
}); | ||
|
||
afterEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
|
||
it("succeeds", async () => { | ||
// Arrange | ||
const getConfigScope = nock("https://api.github.com") | ||
.persist() | ||
.get("/repos/Codertocat/Hello-World/contents/.github/pr-branch-labeler.yml?ref=0123456") | ||
.reply(200, configFixture()); | ||
|
||
const octokit = new github.GitHub("token"); | ||
|
||
const config = await getConfig(octokit, "pr-branch-labeler.yml", context); | ||
|
||
// Assert | ||
expect(getConfigScope.isDone()).toBeTrue(); | ||
expect(config.length).toEqual(6); | ||
expect.assertions(2); | ||
}); | ||
|
||
it("throws an error for an invalid config file", async () => { | ||
|
||
// Arrange | ||
const getConfigScope = nock("https://api.github.com") | ||
.persist() | ||
.get("/repos/Codertocat/Hello-World/contents/.github/pr-branch-labeler.yml?ref=0123456") | ||
.reply(200, configFixture("invalid-config.yml")); | ||
|
||
const octokit = new github.GitHub("token"); | ||
|
||
await expect(getConfig(octokit, "pr-branch-labeler.yml", context)).rejects.toThrow(new Error("config.yml has invalid structure.")); | ||
|
||
// Assert | ||
expect(getConfigScope.isDone()).toBeTrue(); | ||
expect.assertions(2); | ||
}); | ||
|
||
it("throws an error for a directory", async () => { | ||
|
||
// Arrange | ||
const getConfigScope = nock("https://api.github.com") | ||
.persist() | ||
.get("/repos/Codertocat/Hello-World/contents/.github/test?ref=0123456") | ||
.reply(200, []); | ||
|
||
const octokit = new github.GitHub("token"); | ||
|
||
await expect(getConfig(octokit, "test", context)).rejects.toThrow(new Error("test is not a file.")); | ||
|
||
// Assert | ||
expect(getConfigScope.isDone()).toBeTrue(); | ||
expect.assertions(2); | ||
}); | ||
|
||
it("throws an error for no contents", async () => { | ||
|
||
// Arrange | ||
const getConfigScope = nock("https://api.github.com") | ||
.persist() | ||
.get("/repos/Codertocat/Hello-World/contents/.github/pr-branch-labeler.yml?ref=0123456") | ||
.reply(200, emptyConfigFixture()); | ||
|
||
const octokit = new github.GitHub("token"); | ||
|
||
await expect(getConfig(octokit, "pr-branch-labeler.yml", context)).rejects.toThrow(new Error("pr-branch-labeler.yml is empty.")); | ||
|
||
// Assert | ||
expect(getConfigScope.isDone()).toBeTrue(); | ||
expect.assertions(2); | ||
}); | ||
}); |
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
Oops, something went wrong.