Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
43c410d
Add logs
andershagbard Nov 12, 2024
227d763
Update
andershagbard Nov 12, 2024
ac1d454
Update
andershagbard Nov 12, 2024
f3b65d6
Update
andershagbard Nov 12, 2024
cbc7ec7
Update
andershagbard Nov 12, 2024
4254135
Fix
andershagbard Nov 12, 2024
f026bd3
Update
andershagbard Nov 12, 2024
e55f861
Update
andershagbard Nov 12, 2024
4b08459
Update
andershagbard Nov 12, 2024
af07df8
UPDATE
andershagbard Nov 12, 2024
0f29a1b
Update
andershagbard Nov 12, 2024
ca65bad
Update
andershagbard Nov 12, 2024
d477157
Fix
andershagbard Nov 12, 2024
a1df2d1
Revert
andershagbard Nov 12, 2024
c9a27da
Test
andershagbard Nov 12, 2024
dfbeaec
Update
andershagbard Nov 12, 2024
c5a2ac1
Update
andershagbard Nov 13, 2024
6874ff3
Add prettier
andershagbard Nov 13, 2024
de89a97
Update index.js
andershagbard Nov 13, 2024
4b31d3a
Update
andershagbard Nov 13, 2024
16d8acc
Merge pull request #1 from andershagbard/log-test
andershagbard Nov 13, 2024
d20e7d3
Minimize runs
andershagbard Nov 13, 2024
c57a28a
Update addAnnotations.ts
andershagbard Nov 13, 2024
3f8ae4c
Run build
andershagbard Nov 13, 2024
ccbc451
Revert prettier
andershagbard Jun 15, 2025
4ea51f2
Revert more
andershagbard Jun 15, 2025
99115f8
Revert more
andershagbard Jun 15, 2025
c40b7be
More revert
andershagbard Jun 15, 2025
4482f26
Revert
andershagbard Jun 15, 2025
26cbb4c
Update packages
andershagbard Jun 15, 2025
cbc9585
Revert "Update packages"
andershagbard Jun 15, 2025
158ba41
Revert packages
andershagbard Jun 15, 2025
85a1423
Revert more
andershagbard Jun 15, 2025
01123fb
Revert
andershagbard Jun 15, 2025
486431f
Update yarn.lock
andershagbard Jun 15, 2025
8492181
Build file
andershagbard Jun 15, 2025
112504b
Infer type from rest endpoint
andershagbard Jun 15, 2025
e30c6b4
Remove useless assertions
andershagbard Jun 15, 2025
2afec70
Update yarn.lock
andershagbard Jun 15, 2025
e5205a0
Update index.js
andershagbard Jun 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"step:config": "scripts/run-step getConfigContents"
},
"devDependencies": {
"@octokit/plugin-rest-endpoint-methods": "^16.0.0",
"@octokit/webhooks-types": "^7.6.1",
"@types/common-tags": "^1.8.1",
"@types/node": "10.17.60",
"@types/semver": "^7.5.6",
Expand Down
52 changes: 13 additions & 39 deletions src/addAnnotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
import { GitHub, getOctokitOptions } from '@actions/github/lib/utils';
import { throttling } from '@octokit/plugin-throttling';
import { Context } from '@actions/github/lib/context';
import { Octokit } from '@octokit/rest';
import type { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods';
import type { PullRequestEvent } from '@octokit/webhooks-types';
import { stripIndent as markdown } from 'common-tags';
import { ThemeCheckReport, ThemeCheckOffense } from './types';
import * as path from 'path';
Expand All @@ -12,28 +13,7 @@ const ThrottledOctokit = GitHub.plugin(throttling);

const CHECK_NAME = 'Theme Check Report';

// It's really hard to get that type out of their SDK. output?annotations? prevents us from extracting it.
// from node_modules/@octokit/openapi-types/types.d.ts
interface GitHubAnnotation {
/** The path of the file to add an annotation to. For example, `assets/css/main.css`. */
path: string;
/** The start line of the annotation. */
start_line: number;
/** The end line of the annotation. */
end_line: number;
/** The start column of the annotation. Annotations only support `start_column` and `end_column` on the same line. Omit this parameter if `start_line` and `end_line` have different values. */
start_column?: number;
/** The end column of the annotation. Annotations only support `start_column` and `end_column` on the same line. Omit this parameter if `start_line` and `end_line` have different values. */
end_column?: number;
/** The level of the annotation. Can be one of `notice`, `warning`, or `failure`. */
annotation_level: 'notice' | 'warning' | 'failure';
/** A short description of the feedback for these lines of code. The maximum size is 64 KB. */
message: string;
/** The title that represents the annotation. The maximum size is 255 characters. */
title?: string;
/** Details about this annotation. The maximum size is 64 KB. */
raw_details?: string;
}
type GitHubAnnotation = NonNullable<NonNullable<RestEndpointMethodTypes['checks']['update']['parameters']['output']>['annotations']>[number]

const SeverityConversion: {
[k in ThemeCheckOffense['severity']]:
Expand Down Expand Up @@ -75,11 +55,10 @@ export async function addAnnotations(
fileDiff: string[] | undefined,
) {
const cwd = process.cwd();
const ctx = github.context as Context;
const ctx = github.context;
const themeRoot = core.getInput('theme_root');
const version = core.getInput('version');
const flags = core.getInput('flags');

const octokit = new ThrottledOctokit({
...getOctokitOptions(ghToken),
throttle: {
Expand Down Expand Up @@ -109,32 +88,30 @@ export async function addAnnotations(
);
},
},
}) as Octokit;
});

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

const root = path.resolve(cwd, themeRoot);

const result: ThemeCheckReport[] = reports.filter(
getDiffFilter(
root,
path.resolve(cwd, themeRoot),
fileDiff?.map((x) => path.join(cwd, x)),
),
);

// Create check
const prPayload = github.context.payload as PullRequestEvent
const check = await octokit.rest.checks.create({
owner: ctx.repo.owner,
repo: ctx.repo.repo,
...ctx.repo,
name: CHECK_NAME,
head_sha: ctx.sha,
head_sha: github.context.eventName == 'pull_request' ? prPayload.pull_request.head.sha : github.context.sha,
status: 'in_progress',
});

const allAnnotations: GitHubAnnotation[] = result
.flatMap((report: ThemeCheckReport) =>
.flatMap((report) =>
report.offenses.map((offense) => ({
path: path.relative(root, path.resolve(report.path)),
path: path.relative(cwd, path.resolve(report.path)),
start_line: offense.start_row + 1,
end_line: offense.end_row + 1,
start_column:
Expand Down Expand Up @@ -181,8 +158,7 @@ export async function addAnnotations(
await Promise.all(
annotationsChunks.map(async (annotations) =>
octokit.rest.checks.update({
owner: ctx.repo.owner,
repo: ctx.repo.repo,
...ctx.repo,
check_run_id: check.data.id,
output: {
title: CHECK_NAME,
Expand All @@ -195,11 +171,9 @@ export async function addAnnotations(

// Add final report
await octokit.rest.checks.update({
owner: ctx.repo.owner,
repo: ctx.repo.repo,
...ctx.repo,
check_run_id: check.data.id,
name: CHECK_NAME,
status: 'completed',
conclusion: exitCode > 0 ? 'failure' : 'success',
output: {
title: CHECK_NAME,
Expand Down
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
resolved "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.11.0.tgz#da5638d64f2b919bca89ce6602d059f1b52d3ef0"
integrity sha512-VsXyi8peyRq9PqIz/tpqiL2w3w80OgVMwBHltTml3LmVvXiphgeqmY9mvBw9Wu7e0QWk/fqD37ux8yP5uVekyQ==

"@octokit/openapi-types@^25.1.0":
version "25.1.0"
resolved "https://registry.yarnpkg.com/@octokit/openapi-types/-/openapi-types-25.1.0.tgz#5a72a9dfaaba72b5b7db375fd05e90ca90dc9682"
integrity sha512-idsIggNXUKkk0+BExUn1dQ92sfysJrje03Q0bv0e+KPLrvyqZF8MnBpFz8UNfYDwB3Ie7Z0TByjWfzxt7vseaA==

"@octokit/plugin-paginate-rest@^2.16.8", "@octokit/plugin-paginate-rest@^2.17.0":
version "2.21.3"
resolved "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.21.3.tgz#7f12532797775640dbb8224da577da7dc210c87e"
Expand All @@ -125,6 +130,13 @@
resolved "https://registry.npmjs.org/@octokit/plugin-request-log/-/plugin-request-log-1.0.4.tgz#5e50ed7083a613816b1e4a28aeec5fb7f1462e85"
integrity sha512-mLUsMkgP7K/cnFEw07kWqXGF5LKrOkD+lhCrKvPHXWDywAwuDUeDwWBpc69XK3pNX0uKiVt8g5z96PJ6z9xCFA==

"@octokit/plugin-rest-endpoint-methods@^16.0.0":
version "16.0.0"
resolved "https://registry.yarnpkg.com/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-16.0.0.tgz#ba30ca387fc2ac8bd93cf9f951174736babebd97"
integrity sha512-kJVUQk6/dx/gRNLWUnAWKFs1kVPn5O5CYZyssyEoNYaFedqZxsfYs7DwI3d67hGz4qOwaJ1dpm07hOAD1BXx6g==
dependencies:
"@octokit/types" "^14.1.0"

"@octokit/plugin-rest-endpoint-methods@^5.12.0", "@octokit/plugin-rest-endpoint-methods@^5.13.0":
version "5.16.2"
resolved "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.16.2.tgz#7ee8bf586df97dd6868cf68f641354e908c25342"
Expand Down Expand Up @@ -172,13 +184,25 @@
"@octokit/plugin-request-log" "^1.0.4"
"@octokit/plugin-rest-endpoint-methods" "^5.12.0"

"@octokit/types@^14.1.0":
version "14.1.0"
resolved "https://registry.yarnpkg.com/@octokit/types/-/types-14.1.0.tgz#3bf9b3a3e3b5270964a57cc9d98592ed44f840f2"
integrity sha512-1y6DgTy8Jomcpu33N+p5w58l6xyt55Ar2I91RPiIA0xCJBXyUAhXCcmZaDWSANiha7R9a6qJJ2CRomGPZ6f46g==
dependencies:
"@octokit/openapi-types" "^25.1.0"

"@octokit/types@^6.0.1", "@octokit/types@^6.0.3", "@octokit/types@^6.16.1", "@octokit/types@^6.39.0", "@octokit/types@^6.40.0":
version "6.41.0"
resolved "https://registry.npmjs.org/@octokit/types/-/types-6.41.0.tgz#e58ef78d78596d2fb7df9c6259802464b5f84a04"
integrity sha512-eJ2jbzjdijiL3B4PrSQaSjuF2sPEQPVCPzBvTHJD9Nz+9dw2SGH4K4xeQJ77YfTq5bRQ+bD8wT11JbeDPmxmGg==
dependencies:
"@octokit/openapi-types" "^12.11.0"

"@octokit/webhooks-types@^7.6.1":
version "7.6.1"
resolved "https://registry.yarnpkg.com/@octokit/webhooks-types/-/webhooks-types-7.6.1.tgz#bc96371057c2d54c982c9f8f642655b26cd588eb"
integrity sha512-S8u2cJzklBC0FgTwWVLaM8tMrDuDMVE4xiTK4EYXM9GntyvrdbSoxqDQa+Fh57CCNApyIpyeqPhhFEmHPfrXgw==

"@tsconfig/node10@^1.0.7":
version "1.0.9"
resolved "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz#df4907fc07a886922637b15e02d4cebc4c0021b2"
Expand Down