Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[infra] Fix order id validator action #13971

Merged
merged 10 commits into from
Jul 24, 2024
6 changes: 1 addition & 5 deletions .github/workflows/order-id-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ jobs:
with:
script: |
const script = require('./scripts/orderIdValidation.js')
await script(core, github)
await script({core, github, context})
env:
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORDER_API_TOKEN: ${{ secrets.SHOP_AUTH_TOKEN }}
36 changes: 11 additions & 25 deletions scripts/oderIdValidation.js → scripts/orderIdValidation.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
/**
* We import these just for type checking as the actual imports
* are passed as arguments to the function
* https://github.com/marketplace/actions/github-script#run-a-separate-file
* @param {Object} params
* @param {import("@actions/core")} params.core
* @param {ReturnType<import("@actions/github").getOctokit>} params.github
* @param {import("@actions/github").context} params.context
*/

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const core = require('@actions/core');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const github = require('@actions/github');

/**
*
* @param {core} core
* @param {github} github
*/
// eslint-disable-next-line @typescript-eslint/no-shadow
module.exports = async (core, github) => {
module.exports = async ({ core, context, github }) => {
try {
const owner = process.env.OWNER;
const repo = process.env.REPO;
const issueNumber = process.env.ISSUE_NUMBER;
const token = process.env.TOKEN;
const owner = context.repo.owner;
const repo = context.repo.repo;
const issueNumber = context.issue.number;

const orderApiToken = process.env.ORDER_API_TOKEN;
const orderApi = 'https://store-wp.mui.com/wp-json/wc/v3/orders/';

const octokit = github.getOctokit(token);

const issue = octokit.rest.issues.get({
const issue = await github.rest.issues.get({
owner,
repo,
issue_number: issueNumber,
Expand Down Expand Up @@ -59,13 +45,13 @@ module.exports = async (core, github) => {
const planName = plan.match(/\b(pro|premium)\b/i)[0].toLowerCase();
const labelName = `support: ${planName}`;

const label = octokit.rest.issues.getLabel({
const label = await github.rest.issues.getLabel({
owner,
repo,
name: labelName,
});

octokit.rest.issues.addLabels({
await github.rest.issues.addLabels({
owner,
repo,
issue_number: issueNumber,
Expand Down