Preview theme workflow fix (#2557)

* Fix octokit error

* ci: make octokit instance global

---------

Co-authored-by: rickstaa <rick.staa@outlook.com>
This commit is contained in:
Zohan Subhash 2023-03-01 15:03:49 +05:30 committed by GitHub
parent d60d53cdb4
commit 8849b5f5fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.
*
@ -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);
@ -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,
@ -332,7 +334,7 @@ export const run = async (prNumber) => {
});
debug("Retrieve preview-theme comment...");
const comment = await findComment(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,
@ -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,
@ -538,7 +540,7 @@ export const run = async (prNumber) => {
: INVALID_REVIEW_COMMENT(comment_url);
if (!DRY_RUN) {
await addReview(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,
@ -546,7 +548,7 @@ export const run = async (prNumber) => {
reviewReason,
);
await addRemoveLabel(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,
@ -561,7 +563,7 @@ 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,
@ -569,7 +571,7 @@ export const run = async (prNumber) => {
error.message,
);
await addRemoveLabel(
octokit,
OCTOKIT,
pullRequestId,
owner,
repo,