Skip to content

Commit

Permalink
Avoid showing outdated tilde
Browse files Browse the repository at this point in the history
  • Loading branch information
ukupat committed Feb 26, 2024
1 parent 3abbcd6 commit c05fdbf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35919,7 +35919,7 @@ async function run() {
await (0, bash_1.exec)(`git -C ${path} fetch --depth=100 origin main`);
await (0, bash_1.exec)(`git -C ${path} fetch --depth=100 origin +refs/heads/*:refs/remotes/origin/*`);
const commitHash = await (0, bash_1.exec)(`git -C ${path} rev-parse HEAD`);
const branch = (await (0, bash_1.exec)(`git -C ${path} name-rev --name-only HEAD`)).replace('remotes/origin/', '');
const branch = await getBranchName(path);
const behind = await getBehind(path, commitHash);
const ahead = await (0, bash_1.exec)(`git -C ${path} rev-list --count origin/main..HEAD`);
const submoduleName = await (0, bash_1.exec)(`basename $(git -C ${path} rev-parse --show-toplevel)`);
Expand All @@ -35937,6 +35937,10 @@ ${links}`;
await comment(messages.join('\n'));
}
exports.run = run;
async function getBranchName(path) {
const branchName = await (0, bash_1.exec)(`git -C ${path} name-rev --name-only HEAD`);
return branchName.replace('remotes/origin/', '').replace(/~.*$/, '');
}
async function getBehind(path, commitHash) {
const behind = await (0, bash_1.exec)(`git -C ${path} rev-list --count HEAD..origin/main`);
const behindTime = Number(behind) ? await getBehindTime(path, commitHash) : '';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remato/submodule-status-commenter",
"version": "2.0.0",
"version": "2.0.1",
"license": "MIT",
"description": "GitHub action to comment submodules current branch and state to the PR",
"main": "dist/index.js",
Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function run() {
await exec(`git -C ${path} fetch --depth=100 origin +refs/heads/*:refs/remotes/origin/*`)

const commitHash = await exec(`git -C ${path} rev-parse HEAD`)
const branch = (await exec(`git -C ${path} name-rev --name-only HEAD`)).replace('remotes/origin/', '')
const branch = await getBranchName(path)
const behind = await getBehind(path, commitHash)
const ahead = await exec(`git -C ${path} rev-list --count origin/main..HEAD`)
const submoduleName = await exec(`basename $(git -C ${path} rev-parse --show-toplevel)`)
Expand All @@ -37,6 +37,12 @@ ${links}`
await comment(messages.join('\n'))
}

async function getBranchName(path: string) {
const branchName = await exec(`git -C ${path} name-rev --name-only HEAD`)

return branchName.replace('remotes/origin/', '').replace(/~.*$/, '')
}

async function getBehind(path: string, commitHash: string) {
const behind = await exec(`git -C ${path} rev-list --count HEAD..origin/main`)
const behindTime = Number(behind) ? await getBehindTime(path, commitHash) : ''
Expand Down

0 comments on commit c05fdbf

Please sign in to comment.