Skip to content

Commit f6ae145

Browse files
authored
Merge pull request #5 from xt0rted/template-update
Update action code with setup from xt0rted/problem-matcher
2 parents 8a6fdee + 54dc2d9 commit f6ae145

File tree

7 files changed

+36
-20
lines changed

7 files changed

+36
-20
lines changed

.editorconfig

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,13 @@ indent_size = 4
77
indent_style = space
88
trim_trailing_whitespace = true
99

10-
[*.js]
10+
[*.{js,ts}]
1111
end_of_line = lf
1212
indent_size = 2
1313

1414
[*.json]
1515
indent_size = 2
1616

17-
[*.ts]
18-
end_of_line = lf
19-
indent_size = 2
20-
2117
[*.yml]
2218
indent_size = 2
2319

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
__tests__/runner/*
22

3-
# comment out in distribution branches
43
dist/
54

65
node_modules/

.vscode/settings.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cSpell.words": [
3+
"dependabot",
4+
"promisify"
5+
]
6+
}

__tests__/problemMatcher.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { matchResults } from "../__helpers__/utils";
2-
import { problemMatcher as problemMatcherJson } from "../.github/dotnet-format-problem-matcher.json";
2+
import { problemMatcher as problemMatcherJson } from "../.github/problem-matcher.json";
33
import { ProblemMatcher, ProblemPattern } from "github-actions-problem-matcher-typings";
44

5-
const problemMatcher = problemMatcherJson[0] as ProblemMatcher;
5+
const problemMatcher: ProblemMatcher = problemMatcherJson[0];
66

77
describe("problemMatcher", () => {
8+
it("has the correct owner", () => {
9+
expect(problemMatcher.owner).toEqual("dotnet-format");
10+
});
11+
812
it("has one pattern", () => {
913
expect(problemMatcher.pattern.length).toEqual(1);
1014
});
@@ -19,24 +23,21 @@ describe("problemMatcher", () => {
1923
];
2024

2125
let pattern: ProblemPattern;
22-
let regexp: RegExp;
26+
let results: RegExpExecArray[];
2327

2428
beforeEach(() => {
2529
pattern = problemMatcher.pattern[0];
26-
regexp = new RegExp(pattern.regexp);
30+
31+
const regexp = new RegExp(pattern.regexp);
32+
33+
results = matchResults(reportOutput, regexp);
2734
});
2835

2936
it("matches violations", () => {
30-
const results = matchResults(reportOutput, regexp);
31-
3237
expect(results.length).toEqual(2);
3338
});
3439

3540
it("matches violation details", () => {
36-
const results = matchResults(reportOutput, regexp);
37-
38-
expect(results.length).toEqual(2);
39-
4041
expect(results[0][pattern.file]).toEqual("src\\ConsoleApp\\Program.cs");
4142
expect(results[0][pattern.line]).toEqual("5");
4243
expect(results[0][pattern.column]).toEqual("18");

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
"url": "git+https://github.com/xt0rted/dotnet-format-problem-matcher.git"
1717
},
1818
"keywords": [
19-
"actions"
19+
"actions",
20+
"github",
21+
"problem-matcher",
22+
"annotations"
2023
],
2124
"author": "xt0rted",
2225
"license": "MIT",

src/main.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1+
import { readFile } from "fs";
12
import { join } from "path";
3+
import { promisify } from "util";
24

35
import { getInput, setFailed } from "@actions/core";
46
import { issueCommand } from "@actions/core/lib/command"
57

6-
export function run() {
8+
import { ProblemMatcher } from "github-actions-problem-matcher-typings";
9+
10+
const readFileAsync = promisify(readFile);
11+
12+
export async function run(): Promise<void> {
713
try {
814
const action = getInput("action");
915

16+
const matcherFile = join(__dirname, "..", ".github", "problem-matcher.json");
17+
1018
switch (action) {
1119
case "add":
1220
issueCommand(
1321
"add-matcher",
1422
{},
15-
join(__dirname, "..", ".github", "dotnet-format-problem-matcher.json"),
23+
matcherFile,
1624
);
1725
break;
1826

1927
case "remove":
28+
const fileContents = await readFileAsync(matcherFile, { encoding: "utf8" });
29+
const problemMatcher: ProblemMatcher = JSON.parse(fileContents);
30+
2031
issueCommand(
2132
"remove-matcher",
2233
{
23-
owner: "dotnet-format",
34+
owner: problemMatcher.owner,
2435
},
2536
"",
2637
);

0 commit comments

Comments
 (0)