Skip to content

Commit a1c3c6a

Browse files
Zo-Bro-23rickstaa
andauthored
ci: preview theme workflow fix (#2559)
* Fix octokit error * ci: make octokit instance global * Fix preview theme (move declarations to global) * refactor: make constants uppercase --------- Co-authored-by: rickstaa <[email protected]>
1 parent 8849b5f commit a1c3c6a

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

scripts/preview-theme.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const INVALID_REVIEW_COMMENT = (commentUrl) =>
4646

4747
// Retrieve octokit instance.
4848
const OCTOKIT = github.getOctokit(getGithubToken());
49+
const PULL_REQUEST_ID = prNumber ? prNumber : getPrNumber();
50+
const { OWNER, REPO } = getRepoInfo(github.context);
4951

5052
/**
5153
* Retrieve PR number from the event payload.
@@ -315,29 +317,27 @@ export const run = async (prNumber) => {
315317
\r${THEME_CONTRIB_GUIDELINESS}
316318
`;
317319
const ccc = new ColorContrastChecker();
318-
const pullRequestId = prNumber ? prNumber : getPrNumber();
319320
const commenter = getCommenter();
320-
const { owner, repo } = getRepoInfo(github.context);
321-
debug(`Owner: ${owner}`);
322-
debug(`Repo: ${repo}`);
321+
debug(`Owner: ${OWNER}`);
322+
debug(`Repo: ${REPO}`);
323323
debug(`Commenter: ${commenter}`);
324324

325325
// Retrieve the PR diff and preview-theme comment.
326326
debug("Retrieve PR diff...");
327327
const res = await OCTOKIT.pulls.get({
328-
owner,
329-
repo,
330-
pull_number: pullRequestId,
328+
OWNER,
329+
REPO,
330+
pull_number: PULL_REQUEST_ID,
331331
mediaType: {
332332
format: "diff",
333333
},
334334
});
335335
debug("Retrieve preview-theme comment...");
336336
const comment = await findComment(
337337
OCTOKIT,
338-
pullRequestId,
339-
owner,
340-
repo,
338+
PULL_REQUEST_ID,
339+
OWNER,
340+
REPO,
341341
commenter,
342342
);
343343

@@ -519,9 +519,9 @@ export const run = async (prNumber) => {
519519
if (!DRY_RUN) {
520520
comment_url = await upsertComment(OCTOKIT, {
521521
comment_id: comment?.id,
522-
issue_number: pullRequestId,
523-
owner,
524-
repo,
522+
issue_number: PULL_REQUEST_ID,
523+
OWNER,
524+
REPO,
525525
body: commentBody,
526526
});
527527
} else {
@@ -541,17 +541,17 @@ export const run = async (prNumber) => {
541541
if (!DRY_RUN) {
542542
await addReview(
543543
OCTOKIT,
544-
pullRequestId,
545-
owner,
546-
repo,
544+
PULL_REQUEST_ID,
545+
OWNER,
546+
REPO,
547547
reviewState,
548548
reviewReason,
549549
);
550550
await addRemoveLabel(
551551
OCTOKIT,
552-
pullRequestId,
553-
owner,
554-
repo,
552+
PULL_REQUEST_ID,
553+
OWNER,
554+
REPO,
555555
"invalid",
556556
!themesValid,
557557
);
@@ -564,17 +564,17 @@ export const run = async (prNumber) => {
564564
if (!DRY_RUN) {
565565
await addReview(
566566
OCTOKIT,
567-
pullRequestId,
568-
owner,
569-
repo,
567+
PULL_REQUEST_ID,
568+
OWNER,
569+
REPO,
570570
"REQUEST_CHANGES",
571571
error.message,
572572
);
573573
await addRemoveLabel(
574574
OCTOKIT,
575-
pullRequestId,
576-
owner,
577-
repo,
575+
PULL_REQUEST_ID,
576+
OWNER,
577+
REPO,
578578
"invalid",
579579
true,
580580
);

0 commit comments

Comments
 (0)