Skip to content

Commit 4f064ed

Browse files
andershagbardcharlespwd
authored andcommitted
Fix annotations for pull requests (#50)
1 parent c484052 commit 4f064ed

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

dist/index.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"step:config": "scripts/run-step getConfigContents"
99
},
1010
"devDependencies": {
11+
"@octokit/webhooks-types": "^7.6.1",
1112
"@types/common-tags": "^1.8.1",
1213
"@types/node": "10.17.60",
1314
"@types/semver": "^7.5.6",

src/addAnnotations.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GitHub, getOctokitOptions } from '@actions/github/lib/utils';
44
import { throttling } from '@octokit/plugin-throttling';
55
import { Context } from '@actions/github/lib/context';
66
import { Octokit } from '@octokit/rest';
7+
import type { PullRequestEvent } from '@octokit/webhooks-types';
78
import { stripIndent as markdown } from 'common-tags';
89
import { ThemeCheckReport, ThemeCheckOffense } from './types';
910
import * as path from 'path';
@@ -79,7 +80,6 @@ export async function addAnnotations(
7980
const themeRoot = core.getInput('theme_root');
8081
const version = core.getInput('version');
8182
const flags = core.getInput('flags');
82-
8383
const octokit = new ThrottledOctokit({
8484
...getOctokitOptions(ghToken),
8585
throttle: {
@@ -113,28 +113,26 @@ export async function addAnnotations(
113113

114114
console.log('Creating GitHub check...');
115115

116-
const root = path.resolve(cwd, themeRoot);
117-
118116
const result: ThemeCheckReport[] = reports.filter(
119117
getDiffFilter(
120-
root,
118+
path.resolve(cwd, themeRoot),
121119
fileDiff?.map((x) => path.join(cwd, x)),
122120
),
123121
);
124122

125123
// Create check
124+
const prPayload = github.context.payload as PullRequestEvent
126125
const check = await octokit.rest.checks.create({
127-
owner: ctx.repo.owner,
128-
repo: ctx.repo.repo,
126+
...ctx.repo,
129127
name: CHECK_NAME,
130-
head_sha: ctx.sha,
128+
head_sha: github.context.eventName == 'pull_request' ? prPayload.pull_request.head.sha : github.context.sha,
131129
status: 'in_progress',
132130
});
133131

134132
const allAnnotations: GitHubAnnotation[] = result
135-
.flatMap((report: ThemeCheckReport) =>
133+
.flatMap((report) =>
136134
report.offenses.map((offense) => ({
137-
path: path.relative(root, path.resolve(report.path)),
135+
path: path.relative(cwd, path.resolve(report.path)),
138136
start_line: offense.start_row + 1,
139137
end_line: offense.end_row + 1,
140138
start_column:
@@ -181,8 +179,7 @@ export async function addAnnotations(
181179
await Promise.all(
182180
annotationsChunks.map(async (annotations) =>
183181
octokit.rest.checks.update({
184-
owner: ctx.repo.owner,
185-
repo: ctx.repo.repo,
182+
...ctx.repo,
186183
check_run_id: check.data.id,
187184
output: {
188185
title: CHECK_NAME,
@@ -195,11 +192,9 @@ export async function addAnnotations(
195192

196193
// Add final report
197194
await octokit.rest.checks.update({
198-
owner: ctx.repo.owner,
199-
repo: ctx.repo.repo,
195+
...ctx.repo,
200196
check_run_id: check.data.id,
201197
name: CHECK_NAME,
202-
status: 'completed',
203198
conclusion: exitCode > 0 ? 'failure' : 'success',
204199
output: {
205200
title: CHECK_NAME,

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@
179179
dependencies:
180180
"@octokit/openapi-types" "^12.11.0"
181181

182+
"@octokit/webhooks-types@^7.6.1":
183+
version "7.6.1"
184+
resolved "https://registry.yarnpkg.com/@octokit/webhooks-types/-/webhooks-types-7.6.1.tgz#bc96371057c2d54c982c9f8f642655b26cd588eb"
185+
integrity sha512-S8u2cJzklBC0FgTwWVLaM8tMrDuDMVE4xiTK4EYXM9GntyvrdbSoxqDQa+Fh57CCNApyIpyeqPhhFEmHPfrXgw==
186+
182187
"@tsconfig/node10@^1.0.7":
183188
version "1.0.9"
184189
resolved "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2"

0 commit comments

Comments
 (0)