Skip to content

Commit

Permalink
Preview theme workflow fix (anuraghazra#2557)
Browse files Browse the repository at this point in the history
* Fix octokit error

* ci: make octokit instance global

---------

Co-authored-by: rickstaa <rick.staa@outlook.com>
  • Loading branch information
2 people authored and devantler committed May 1, 2023
1 parent 817deb7 commit 2c23b92
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions scripts/preview-theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const REQUIRED_COLOR_PROPS = ACCEPTED_COLOR_PROPS.slice(0, 4);
const INVALID_REVIEW_COMMENT = (commentUrl) =>
`Some themes are invalid. See the [Automated Theme Preview](${commentUrl}) comment above for more information.`;

// Retrieve octokit instance.
const OCTOKIT = github.getOctokit(getGithubToken());

/**
* Retrieve PR number from the event payload.
*
Expand Down Expand Up @@ -312,7 +315,6 @@ export const run = async (prNumber) => {
\r${THEME_CONTRIB_GUIDELINESS}
`;
const ccc = new ColorContrastChecker();
const octokit = github.getOctokit(getGithubToken());
const pullRequestId = prNumber ? prNumber : getPrNumber();
const commenter = getCommenter();
const { owner, repo } = getRepoInfo(github.context);
Expand All @@ -322,7 +324,7 @@ export const run = async (prNumber) => {

// Retrieve the PR diff and preview-theme comment.
debug("Retrieve PR diff...");
const res = await octokit.pulls.get({
const res = await OCTOKIT.pulls.get({
owner,
repo,
pull_number: pullRequestId,
Expand All @@ -332,7 +334,7 @@ export const run = async (prNumber) => {
});
debug("Retrieve preview-theme comment...");
const comment = await findComment(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,
Expand Down Expand Up @@ -515,7 +517,7 @@ export const run = async (prNumber) => {
debug("Create or update theme-preview comment...");
let comment_url;
if (!DRY_RUN) {
comment_url = await upsertComment(octokit, {
comment_url = await upsertComment(OCTOKIT, {
comment_id: comment?.id,
issue_number: pullRequestId,
owner,
Expand All @@ -538,15 +540,15 @@ export const run = async (prNumber) => {
: INVALID_REVIEW_COMMENT(comment_url);
if (!DRY_RUN) {
await addReview(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,
reviewState,
reviewReason,
);
await addRemoveLabel(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,
Expand All @@ -561,15 +563,15 @@ export const run = async (prNumber) => {
debug("Set review state to `REQUEST_CHANGES` and add `invalid` label...");
if (!DRY_RUN) {
await addReview(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,
"REQUEST_CHANGES",
error.message,
);
await addRemoveLabel(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,
Expand Down

0 comments on commit 2c23b92

Please sign in to comment.