Skip to content

Commit

Permalink
fix: changed git_repo_url search
Browse files Browse the repository at this point in the history
  • Loading branch information
Demian222 authored Oct 6, 2023
1 parent 768a71b commit 2dfe277
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/bash/src/main/sh/buildstamp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ if [[ $opt_git == "true" ]]; then
git_commit_branch = $(git rev-parse --abbrev-ref HEAD)
fi
git_commit_id=$(git rev-parse HEAD)
git_repo_url=$(git config --get remote.origin.url)
git_remote=$(git remote show)
git_repo_url=$(git config --get remote.${git_remote}.url)
re="([^./:]+\/[^./]+)(\.git)?$"
if [[ $git_repo_url =~ $re ]]; then
git_repo_name=${BASH_REMATCH[1]}
Expand Down
9 changes: 8 additions & 1 deletion packages/bin/src/main/go/buildstamp/buildstamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func GetPkgInfo(cwd string) PackageJson {

func GetGitInfo(cwd string) GitInfo {
var _, commitId, _ = invoke("git", []string{"rev-parse", "HEAD"}, cwd)
var _, repoUrl, _ = invoke("git", []string{"config", "--get", "remote.origin.url"}, cwd)
var repoUrl = getGitRepoUrl(cwd)
var repoName = string(repoUrl[strings.LastIndex(repoUrl, ":")+1 : strings.LastIndex(repoUrl, ".")])
var commitBranch = getCommitBranch(cwd)

Expand All @@ -86,6 +86,13 @@ func GetGitInfo(cwd string) GitInfo {
}
}

func getGitRepoUrl(cwd string) string {
var _, remote, _ = invoke("git", []string{"remote", "show"}, cwd)
var _, repoUrl, _ = invoke("git", []string{"config", "--get", "remote." + remote + ".url"}, cwd)

return repoUrl
}

func getCommitBranch(cwd string) string {
var commitBranch = getFirstNonEmpty(os.Getenv("CI_COMMIT_BRANCH"), os.Getenv("GITHUB_REF_NAME"))
if commitBranch == "" {
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/main/ts/buildstamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const getCommitBranch = async (cwd: string, env: Record<string, string |

export const getGitInfo = async (cwd: string, env: Record<string, string | undefined>): Promise<IGitInfo> => {
const { stdout: git_commit_id } = await spawn('git', ['rev-parse', 'HEAD'], cwd)
const { stdout: git_repo_url } = await spawn('git', ['config', '--get', 'remote.origin.url'], cwd)
const git_repo_url = await getGitRepoUrl(cwd)
const git_commit_branch = await getCommitBranch(cwd, env)
const git_repo_name = (git_repo_url.match(/([^./:]+\/[^./]+)(\.git)?$/) || [])[1]

Expand All @@ -65,6 +65,12 @@ export const getGitInfo = async (cwd: string, env: Record<string, string | undef
}
}

const getGitRepoUrl = async (cwd: string): Promise<string> => {
const { stdout: git_remote } = await spawn('git', ['remote', 'show'], cwd)
const { stdout: git_repo_url } = await spawn('git', ['config', '--get', `remote.${git_remote}.url`], cwd)
return git_repo_url
}

// https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
// https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
// https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#Predefined+Server+Build+Parameters
Expand Down

0 comments on commit 2dfe277

Please sign in to comment.