Bugfix: Updates Diff Hashes (#106)

Rather than using branch names we are using the hashes provided directly in the Gitlab API response, to compare the point at which the branch diverged from the target to the head commit. We are additionally flashing a warning if the MR contains a merge conflict.
This commit is contained in:
Harrison (Harry) Cramer
2023-11-20 07:19:20 -05:00
committed by GitHub
parent b1b3448dcb
commit b8c386ac6b
5 changed files with 78 additions and 12 deletions

View File

@@ -27,8 +27,15 @@ Extracts information about the current repository and returns
it to the client for initialization. The current directory must be a valid
Gitlab project and the branch must be a feature branch
*/
func ExtractGitInfo(getProjectRemoteUrl func() (string, error), getCurrentBranchName func() (string, error)) (GitProjectInfo, error) {
func ExtractGitInfo(refreshGitInfo func() error, getProjectRemoteUrl func() (string, error), getCurrentBranchName func() (string, error)) (GitProjectInfo, error) {
err := refreshGitInfo()
if err != nil {
return GitProjectInfo{}, fmt.Errorf("Could not get latest information from remote: %v", err)
}
url, err := getProjectRemoteUrl()
if err != nil {
return GitProjectInfo{}, fmt.Errorf("Could not get project Url: %v", err)
}
@@ -97,3 +104,14 @@ func GetProjectUrlFromNativeGitCmd() (string, error) {
return strings.TrimSpace(string(url)), nil
}
/* Pulls down latest commit information from Gitlab */
func RefreshProjectInfo() error {
cmd := exec.Command("git", "fetch", "origin")
_, err := cmd.Output()
if err != nil {
return fmt.Errorf("Failed to run `git fetch origin`: %v", err)
}
return nil
}