-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Remove Requirement for Dotfile (#84)
This MR removes the requirement for a dotfile (the dotfile is now optional and will override the configuration provided via environment variables). The requirement for providing a project ID is also eliminated, by parsing the namespace and project name from the SSH or HTTPS remote, and then using that to query Gitlab for a matching project.
- v3.3.12
- v3.3.11
- v3.3.10
- v3.3.9
- v3.3.8
- v3.3.7
- v3.3.6
- v3.3.5
- v3.3.4
- v3.3.3
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.1
- v3.0.0
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.4
- v2.6.3
- v2.6.2
- v2.6.1
- v2.6.0
- v2.5.0
- v2.4.1
- v2.4.0
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.15
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
1 parent
38df51b
commit 80b597e
Showing
8 changed files
with
215 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
/* | ||
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() (string, string, string, string, error) { | ||
|
||
url, err := getProjectUrl() | ||
if err != nil { | ||
return "", "", "", "", fmt.Errorf("Could not get project Url: %v", err) | ||
} | ||
|
||
re := regexp.MustCompile(`(?:[:\/])([^\/]+)\/([^\/]+)\.git$`) | ||
matches := re.FindStringSubmatch(url) | ||
if len(matches) != 3 { | ||
return "", "", "", "", fmt.Errorf("Invalid Git URL format: %s", url) | ||
} | ||
|
||
namespace := matches[1] | ||
projectName := matches[2] | ||
|
||
branch, err := getCurrentBranch() | ||
if err != nil { | ||
return "", "", "", "", fmt.Errorf("Failed to get current branch: %v", err) | ||
} | ||
|
||
return url, namespace, projectName, branch, nil | ||
} | ||
|
||
/* Gets the current branch */ | ||
func getCurrentBranch() (res string, e error) { | ||
gitCmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD") | ||
|
||
output, err := gitCmd.Output() | ||
if err != nil { | ||
return "", fmt.Errorf("Error running git rev-parse: %w", err) | ||
} | ||
|
||
branchName := strings.TrimSpace(string(output)) | ||
|
||
if branchName == "main" || branchName == "master" { | ||
return "", fmt.Errorf("Cannot run on %s branch", branchName) | ||
} | ||
|
||
return branchName, nil | ||
} | ||
|
||
/* Gets the project SSH or HTTPS url */ | ||
func getProjectUrl() (res string, e error) { | ||
cmd := exec.Command("git", "remote", "get-url", "origin") | ||
url, err := cmd.Output() | ||
|
||
if err != nil { | ||
return "", fmt.Errorf("Could not get origin remote") | ||
} | ||
|
||
return strings.TrimSpace(string(url)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters