Skip to content

Commit

Permalink
pr
Browse files Browse the repository at this point in the history
  • Loading branch information
maxprilutskiy committed Oct 7, 2024
1 parent 52208eb commit 606fa19
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ jobs:
uses: ./
with:
commit-message: 'feat: update some data'
pull-request: true
pull-request-title: 'feat: pr with some data updates'
env:
GH_TOKEN: ${{ github.token }}
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ runs:
REPLEXICA_API_KEY: ${{ inputs.api-key }}
REPLEXICA_PULL_REQUEST: ${{ inputs.pull-request }}
REPLEXICA_COMMIT_MESSAGE: ${{ inputs.commit-message }}
REPLEXICA_PULL_REQUEST_TITLE: ${{ inputs.pull-request-title }}

inputs:
api-key:
Expand All @@ -24,3 +25,6 @@ inputs:
commit-message:
description: 'Commit message'
required: false
pull-request-title:
description: 'Pull request title'
required: false
2 changes: 1 addition & 1 deletion action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
},
"dependencies": {
"octokit": "^4.0.2",
"typescript": "^5.6.2",
"zod": "^3.23.8"
},
"devDependencies": {
"typescript": "^5.6.2",
"@types/node": "^22.7.4"
}
}
25 changes: 22 additions & 3 deletions action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,27 @@ import doStuff from './do-stuff.js';
execSync('git config --global user.email "support@replexica.com"');
execSync(`git config --global safe.directory ${process.cwd()}`);

execSync('git add .');
execSync(`git commit -m "${config.commitMessageText}"`);
execSync('git push');
if (!config.isPullRequestMode) {
execSync('git add .');
execSync(`git commit -m "${config.commitMessage}"`);
execSync('git push');
} else {
// Calculate automated branch name
const prBranchName = `replexica/${config.currentBranchName}`;

// Create branch
execSync(`git checkout -b ${prBranchName}`);
execSync('git add .');
execSync(`git commit -m "${config.commitMessage}"`);
execSync('git push --set-upstream origin ${prBranchName}');

// Create PR
await octokit.rest.pulls.create({
owner: config.repositoryOwner,
repo: config.repositoryName,
head: prBranchName,
base: config.currentBranchName,
title: config.pullRequestTitle,
});
}
})();
1 change: 1 addition & 0 deletions action/src/instances/_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default async function loadEnv() {
REPLEXICA_API_KEY: Z.string(),
REPLEXICA_PULL_REQUEST: Z.preprocess(Boolean, Z.boolean()).default(false),
REPLEXICA_COMMIT_MESSAGE: Z.string().default('feat: update translations'),
REPLEXICA_PULL_REQUEST_TITLE: Z.string().default('feat: update translations'),
// Github
GITHUB_REPOSITORY: Z.string(),
GITHUB_REPOSITORY_OWNER: Z.string(),
Expand Down
7 changes: 6 additions & 1 deletion action/src/instances/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ export default async function loadConfig() {

return {
isPullRequestMode: env.REPLEXICA_PULL_REQUEST,
commitMessageText: env.REPLEXICA_COMMIT_MESSAGE,
commitMessage: env.REPLEXICA_COMMIT_MESSAGE,
pullRequestTitle: env.REPLEXICA_PULL_REQUEST_TITLE,
currentBranchName: env.GITHUB_REF_NAME,
repositoryOwner: env.GITHUB_REPOSITORY_OWNER,
repositoryFullName: env.GITHUB_REPOSITORY,
repositoryName: env.GITHUB_REPOSITORY.split('/')[1],
};
}

0 comments on commit 606fa19

Please sign in to comment.