Skip to content

Commit

Permalink
Fix last commit reference
Browse files Browse the repository at this point in the history
  • Loading branch information
ukupat committed Feb 4, 2024
1 parent c398d47 commit 6356da0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
15 changes: 9 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35913,7 +35913,6 @@ exports.run = void 0;
const moment_1 = __importDefault(__nccwpck_require__(9623));
const githubRequests_1 = __nccwpck_require__(2963);
const bash_1 = __nccwpck_require__(9134);
const github_1 = __nccwpck_require__(5438);
async function run(path) {
await (0, bash_1.exec)(`git -C ${path} fetch --depth=50 origin +refs/heads/*:refs/remotes/origin/*`);
const commitHash = await (0, bash_1.exec)(`git -C ${path} rev-parse HEAD`);
Expand All @@ -35923,7 +35922,6 @@ async function run(path) {
const submoduleName = await (0, bash_1.exec)(`basename $(git -C ${path} rev-parse --show-toplevel)`);
const lastCommit = await getLastCommit(path);
const links = await getLinks(path, commitHash, branch);
console.log('Workflow', github_1.context.workflow);
await comment(submoduleName, `**Submodule "${submoduleName}" status**

- Current branch: **${branch}**
Expand All @@ -35948,9 +35946,15 @@ async function getBehindTime(path, commitHash) {
return timeDiff.humanize();
}
async function getLastCommit(path) {
const lastCommitMessage = await (0, bash_1.exec)(`git -C ${path} log -1 --pretty=format:%s`);
const lastCommitAuthor = await (0, bash_1.exec)(`git -C ${path} log -1 --pretty=%an`);
return `"${lastCommitMessage.trim().substring(0, 50)}" by ${lastCommitAuthor.trim()}`;
const submodule = await (0, bash_1.exec)(`git -C ${path} remote get-url origin | sed -e 's/.*:\/\/github.com\///' -e 's/.*:\/\///' -e 's/\.git$//'
`);
const author = await (0, bash_1.exec)(`git -C ${path} log -1 --pretty=%an`);
const message = await (0, bash_1.exec)(`git -C ${path} log -1 --pretty=format:%s`);
const formattedMessage = message
.trim()
.substring(0, 50)
.replace('Merge pull request #', `Merge pull request ${submodule}#`);
return `"${formattedMessage.trim().substring(0, submodule.length + 50)}" by ${author.trim()}`;
}
async function getLinks(path, commitHash, branch) {
const submoduleUrl = (await (0, bash_1.exec)(`git -C ${path} config --get remote.origin.url`)).replace('.git', '');
Expand All @@ -35964,7 +35968,6 @@ function getExactStateLink(submoduleUrl, commitHash) {
}
async function getSubmodulePullRequestLink(branch, submoduleUrl) {
const pr = await getSubmodulePullRequestByBranchName(branch, submoduleUrl);
console.log('PR debug', pr, branch, submoduleUrl);
return pr ? `[View ${pr.state} PR](${pr.html_url})` : '';
}
async function getSubmodulePullRequestByBranchName(branchName, submoduleUrl) {
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": "1.0.0",
"version": "1.0.1",
"license": "MIT",
"description": "GitHub action to comment submodules current branch and state to the PR",
"main": "dist/index.js",
Expand Down
20 changes: 11 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
updatePullRequestComment,
} from './githubRequests'
import { exec } from './bash'
import { context } from '@actions/github'

export async function run(path: string) {
await exec(`git -C ${path} fetch --depth=50 origin +refs/heads/*:refs/remotes/origin/*`)
Expand All @@ -19,8 +18,6 @@ export async function run(path: string) {
const lastCommit = await getLastCommit(path)
const links = await getLinks(path, commitHash, branch)

console.log('Workflow', context.workflow)

await comment(
submoduleName,
`**Submodule "${submoduleName}" status**
Expand Down Expand Up @@ -54,10 +51,17 @@ async function getBehindTime(path: string, commitHash: string) {
}

async function getLastCommit(path: string) {
const lastCommitMessage = await exec(`git -C ${path} log -1 --pretty=format:%s`)
const lastCommitAuthor = await exec(`git -C ${path} log -1 --pretty=%an`)

return `"${lastCommitMessage.trim().substring(0, 50)}" by ${lastCommitAuthor.trim()}`
const submodule =
await exec(`git -C ${path} remote get-url origin | sed -e 's/.*:\/\/github.com\///' -e 's/.*:\/\///' -e 's/\.git$//'
`)
const author = await exec(`git -C ${path} log -1 --pretty=%an`)
const message = await exec(`git -C ${path} log -1 --pretty=format:%s`)
const formattedMessage = message
.trim()
.substring(0, 50)
.replace('Merge pull request #', `Merge pull request ${submodule}#`)

return `"${formattedMessage.trim().substring(0, submodule.length + 50)}" by ${author.trim()}`
}

async function getLinks(path: string, commitHash: string, branch: string) {
Expand All @@ -77,8 +81,6 @@ function getExactStateLink(submoduleUrl: string, commitHash: string) {
async function getSubmodulePullRequestLink(branch: string, submoduleUrl: string) {
const pr = await getSubmodulePullRequestByBranchName(branch, submoduleUrl)

console.log('PR debug', pr, branch, submoduleUrl)

return pr ? `[View ${pr.state} PR](${pr.html_url})` : ''
}

Expand Down

0 comments on commit 6356da0

Please sign in to comment.