Skip to content

Commit

Permalink
Fetching files for detecting react component in GH action
Browse files Browse the repository at this point in the history
  • Loading branch information
sebryu committed Sep 26, 2023
1 parent 624148c commit 92ef0f4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 30 deletions.
28 changes: 13 additions & 15 deletions .github/actions/javascript/authorChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,12 @@ module.exports = generateDynamicChecksAndCheckForCompletion;

const { parse } = __nccwpck_require__(639);
const traverse = __nccwpck_require__(5008).default;
const github = __nccwpck_require__(5438);
const _ = __nccwpck_require__(2947);
const fs = __nccwpck_require__(5747);
const path = __nccwpck_require__(5622);
const CONST = __nccwpck_require__(4097);
const GithubUtils = __nccwpck_require__(7999);

const items = [
"I verified that similar component doesn't exist in the codebase",
Expand Down Expand Up @@ -248,28 +250,24 @@ function detectReactComponent(code) {
return isReactComponent;
};

function readFile(filename) {
const filePath = path.resolve(__dirname, `../../../../${filename}`);
const filePath2 = path.resolve(filename);

function fetchFile(filename) {
console.log('debug', github.context.payload.pull_request);
const content = {
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
path: filename,
ref: github.context.payload.pull_request.head.ref,
};
try {
console.log('reading', filePath2, fs.existsSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json')));
return fs.readFileSync(filePath2, 'utf-8');
return GithubUtils.octokit.rest.repos.getContent(content);
} catch (error) {
console.error(`Error reading ${filePath2}`, error);
console.error(`An unknown error occurred with the GitHub API: ${error}, while fetching ${content}`);
}
}

function detectFunction(changedFiles) {
console.log('detectFunction', process.cwd(), __dirname, process.env.GITHUB_WORKSPACE, path.join(process.env.GITHUB_WORKSPACE, 'package.json'));

fs.readdirSync(__dirname).forEach(file => {
console.log(file);
});


const filteredFiles = _.filter((changedFiles), ({ filename }) => filename.endsWith('.js') || filename.endsWith('.jsx') || filename.endsWith('.ts') || filename.endsWith('.tsx'));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(readFile(filename)));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(fetchFile(filename)));
}

module.exports = {
Expand Down
28 changes: 13 additions & 15 deletions .github/actions/javascript/authorChecklist/newComponentCategory.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const { parse } = require('@babel/parser');
const traverse = require('@babel/traverse').default;
const github = require('@actions/github');
const _ = require('underscore');
const fs = require('fs');
const path = require('path');
const CONST = require('../../../libs/CONST');
const GithubUtils = require('../../../libs/GithubUtils');

const items = [
"I verified that similar component doesn't exist in the codebase",
Expand Down Expand Up @@ -48,28 +50,24 @@ function detectReactComponent(code) {
return isReactComponent;
};

function readFile(filename) {
const filePath = path.resolve(__dirname, `../../../../${filename}`);
const filePath2 = path.resolve(filename);

function fetchFile(filename) {
console.log('debug', github.context.payload.pull_request);
const content = {
owner: CONST.GITHUB_OWNER,
repo: CONST.APP_REPO,
path: filename,
ref: github.context.payload.pull_request.head.ref,
};
try {
console.log('reading', filePath2, fs.existsSync(path.join(process.env.GITHUB_WORKSPACE, 'package.json')));
return fs.readFileSync(filePath2, 'utf-8');
return GithubUtils.octokit.rest.repos.getContent(content);
} catch (error) {
console.error(`Error reading ${filePath2}`, error);
console.error(`An unknown error occurred with the GitHub API: ${error}, while fetching ${content}`);
}
}

function detectFunction(changedFiles) {
console.log('detectFunction', process.cwd(), __dirname, process.env.GITHUB_WORKSPACE, path.join(process.env.GITHUB_WORKSPACE, 'package.json'));

fs.readdirSync(__dirname).forEach(file => {
console.log(file);
});


const filteredFiles = _.filter((changedFiles), ({ filename }) => filename.endsWith('.js') || filename.endsWith('.jsx') || filename.endsWith('.ts') || filename.endsWith('.tsx'));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(readFile(filename)));
return _.some(filteredFiles, ({ filename }) => detectReactComponent(fetchFile(filename)));
}

module.exports = {
Expand Down

0 comments on commit 92ef0f4

Please sign in to comment.