diff --git a/scripts/on-update-datanode-hook.js b/scripts/on-update-datanode-hook.js index 7e613b721..70735700d 100644 --- a/scripts/on-update-datanode-hook.js +++ b/scripts/on-update-datanode-hook.js @@ -107,8 +107,9 @@ const run = async ({ if (unstagedFiles.length) { launchGitWorkflow({ - apiVersion, - apiCommitHash, + branchName: TYPE_UPDATE_BRANCH, + frontendRepoOwner, + frontendRepoName, commitMessage: `update types for v${apiVersion} on HEAD:${apiCommitHash}`, }); diff --git a/scripts/on-update-network-hook.js b/scripts/on-update-network-hook.js index ad7b3f5b3..f9785ffc0 100644 --- a/scripts/on-update-network-hook.js +++ b/scripts/on-update-network-hook.js @@ -1,10 +1,10 @@ const fs = require('node:fs'); const path = require('node:path'); -const { execSync } = require('node:child_process'); const execWrap = require('./utils/exec-wrap'); const githubRequest = require('./utils/github-request'); const wrapCli = require('./utils/wrap-cli'); +const launchGitWorkflow = require('./utils/git-workflow'); const launchGithubWorkflow = require('./utils/github-workflow'); const NETWORK_UPDATE_BRANCH = 'fix/networks'; @@ -119,10 +119,13 @@ const run = async ({ .split('\n') .filter((file) => file !== ''); + console.log(frontendRepoOwner, frontendRepoName) + if (unstagedFiles.length) { launchGitWorkflow({ - apiVersion, - apiCommitHash, + branchName: NETWORK_UPDATE_BRANCH, + frontendRepoOwner, + frontendRepoName, commitMessage: `update networks based on ${networkRepoOwner}/${networkRepoName} HEAD:${networkCommitHash}`, }); diff --git a/scripts/utils/git-workflow.js b/scripts/utils/git-workflow.js index bc3186be6..e46905321 100644 --- a/scripts/utils/git-workflow.js +++ b/scripts/utils/git-workflow.js @@ -1,11 +1,14 @@ +const execWrap = require('./exec-wrap'); + module.exports = ({ + branchName, commitMessage, frontendRepoOwner, frontendRepoName, }) => { const remoteBranches = execWrap({ - cmd: `git ls-remote --heads ssh://github.com/${frontendRepoOwner}/${frontendRepoName}.git ${TYPE_UPDATE_BRANCH}`, - errMessage: `Error checking if the branch "${TYPE_UPDATE_BRANCH}" exists on the origin.`, + cmd: `git ls-remote --heads ssh://github.com/${frontendRepoOwner}/${frontendRepoName}.git ${branchName}`, + errMessage: `Error checking if the branch "${branchName}" exists on the origin.`, }); const localBranches = execWrap({ cmd: 'git branch', @@ -13,24 +16,24 @@ module.exports = ({ }); if ( - remoteBranches.includes(TYPE_UPDATE_BRANCH) || - localBranches.includes(TYPE_UPDATE_BRANCH) + remoteBranches.includes(branchName) || + localBranches.includes(branchName) ) { const currentBranchName = execWrap({ cmd: `git branch --show-current`, errMessage: `Error getting current branch name.`, }); - if (currentBranchName !== TYPE_UPDATE_BRANCH) { + if (currentBranchName !== branchName) { execWrap({ - cmd: `git checkout ${TYPE_UPDATE_BRANCH}`, - errMessage: `There was an error trying to check out the branch "${TYPE_UPDATE_BRANCH}".`, + cmd: `git checkout ${branchName}`, + errMessage: `There was an error trying to check out the branch "${branchName}".`, }); } } else { execWrap({ - cmd: `git checkout -b ${TYPE_UPDATE_BRANCH}`, - errMessage: `There was an error trying to check out the branch "${TYPE_UPDATE_BRANCH}".`, + cmd: `git checkout -b ${branchName}`, + errMessage: `There was an error trying to check out the branch "${branchName}".`, }); } @@ -41,11 +44,11 @@ module.exports = ({ execWrap({ cmd: `git commit -m 'chore: ${commitMessage}' --no-verify`, - errMessage: `Error checking if the branch "${TYPE_UPDATE_BRANCH}" exists on the origin.`, + errMessage: `Error checking if the branch "${branchName}" exists on the origin.`, }); execWrap({ - cmd: `git push -u ssh://github.com/${frontendRepoOwner}/${frontendRepoName}.git ${TYPE_UPDATE_BRANCH} --no-verify`, + cmd: `git push -u ssh://github.com/${frontendRepoOwner}/${frontendRepoName}.git ${branchName} --no-verify`, errMessage: 'Error pushing changes.', }); }; diff --git a/scripts/utils/github-request.js b/scripts/utils/github-request.js index 2201eb22f..89cbb8554 100644 --- a/scripts/utils/github-request.js +++ b/scripts/utils/github-request.js @@ -1,6 +1,7 @@ +const https = require('node:https'); const request = require('./request'); -module.exports = async (url, { body }) => { +module.exports = async (url, { githubAuthToken, body }) => { const options = { method: 'POST', headers: { diff --git a/scripts/utils/github-workflow.js b/scripts/utils/github-workflow.js index 4ac017354..fd1e68c7a 100644 --- a/scripts/utils/github-workflow.js +++ b/scripts/utils/github-workflow.js @@ -1,3 +1,5 @@ +const githubRequest = require('./github-request'); + module.exports = async ({ issueBody, prBody, @@ -8,6 +10,7 @@ module.exports = async ({ const { number, html_url: issueHtmlUrl } = await githubRequest( `https://api.github.com/repos/${frontendRepoOwner}/${frontendRepoName}/issues`, { + githubAuthToken, body: JSON.stringify(issueBody), } ); @@ -17,6 +20,7 @@ module.exports = async ({ const { html_url: prHtmlUrl } = await githubRequest( `https://api.github.com/repos/${frontendRepoOwner}/${frontendRepoName}/pulls`, { + githubAuthToken, body: JSON.stringify({ base: prBody.base || 'master', title: `fix/${number}: ${prBody.title}`, diff --git a/scripts/utils/parse-cli-args.js b/scripts/utils/parse-cli-args.js index ce25de7a3..e1cdfa278 100644 --- a/scripts/utils/parse-cli-args.js +++ b/scripts/utils/parse-cli-args.js @@ -16,7 +16,7 @@ module.exports = ({ specs, args = [] }) => { } return { ...acc, - [spec.name]: value, + [spec.name]: value || spec.default, }; }, {}); };