-
Notifications
You must be signed in to change notification settings - Fork 558
FEATURE: Azure gitops support #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
f16acec
git azure service added
vikramdevtron 41ad752
Merge branch 'main' into azure-git-support
vikramdevtron 94ef423
wip
vikramdevtron e99da4f
wip
vikramdevtron 9f2552c
wip
vikramdevtron 15fcb60
azure devops support dev
d27e21c
git provider type correction
0d5c5e4
error handling correction
90353e2
error handling for branch creation
036348b
branch error check fix
4378b10
add git binary
784bf93
add git binary
d358723
local tested
dc33ee8
fix azure gitops startup
00d71fc
git clone fix
78980f3
log corection
5339437
review fix
8268691
for loop simplification
e6d3f59
db migration added
12eabcc
gitops config default handling
0183dad
slow git clone handling
468a21b
Merge remote-tracking branch 'origin/main' into azure-git-support
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,7 @@ | ||
| #!/bin/sh | ||
| # This script is used as the command supplied to GIT_ASKPASS as a way to supply username/password | ||
| # credentials to git, without having to use git credentials helpers, or having on-disk config. | ||
| case "$1" in | ||
| Username*) echo "${GIT_USERNAME}" ;; | ||
| Password*) echo "${GIT_PASSWORD}" ;; | ||
| esac |
This file contains hidden or 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 hidden or 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,105 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "go.uber.org/zap" | ||
| "gopkg.in/src-d/go-git.v4" | ||
| "gopkg.in/src-d/go-git.v4/config" | ||
| "os" | ||
| "os/exec" | ||
| "strings" | ||
| ) | ||
|
|
||
| type GitCliUtil struct { | ||
| logger *zap.SugaredLogger | ||
| } | ||
|
|
||
| func NewGitCliUtil(logger *zap.SugaredLogger) *GitCliUtil { | ||
| return &GitCliUtil{ | ||
| logger: logger, | ||
| } | ||
| } | ||
|
|
||
| const GIT_ASK_PASS = "/git-ask-pass.sh" | ||
|
|
||
| func (impl *GitCliUtil) Fetch(rootDir string, username string, password string) (response, errMsg string, err error) { | ||
| impl.logger.Debugw("git fetch ", "location", rootDir) | ||
| cmd := exec.Command("git", "-C", rootDir, "fetch", "origin", "--tags", "--force") | ||
| output, errMsg, err := impl.runCommandWithCred(cmd, username, password) | ||
| impl.logger.Debugw("fetch output", "root", rootDir, "opt", output, "errMsg", errMsg, "error", err) | ||
| return output, errMsg, err | ||
| } | ||
|
|
||
| func (impl *GitCliUtil) Pull(rootDir string, username string, password string, branch string) (response, errMsg string, err error) { | ||
| impl.logger.Debugw("git pull ", "location", rootDir) | ||
| cmd := exec.Command("git", "-C", rootDir, "pull", "origin", branch, "--force") | ||
| output, errMsg, err := impl.runCommandWithCred(cmd, username, password) | ||
| impl.logger.Debugw("pull output", "root", rootDir, "opt", output, "errMsg", errMsg, "error", err) | ||
| return output, errMsg, err | ||
| } | ||
| func (impl *GitCliUtil) Checkout(rootDir string, branch string) (response, errMsg string, err error) { | ||
| impl.logger.Debugw("git checkout ", "location", rootDir) | ||
| cmd := exec.Command("git", "-C", rootDir, "checkout", branch, "--force") | ||
| output, errMsg, err := impl.runCommand(cmd) | ||
| impl.logger.Debugw("checkout output", "root", rootDir, "opt", output, "errMsg", errMsg, "error", err) | ||
| return output, errMsg, err | ||
| } | ||
|
|
||
| func (impl *GitCliUtil) runCommandWithCred(cmd *exec.Cmd, userName, password string) (response, errMsg string, err error) { | ||
| cmd.Env = append(os.Environ(), | ||
| fmt.Sprintf("GIT_ASKPASS=%s", GIT_ASK_PASS), | ||
| fmt.Sprintf("GIT_USERNAME=%s", userName), | ||
| fmt.Sprintf("GIT_PASSWORD=%s", password), | ||
| ) | ||
| return impl.runCommand(cmd) | ||
| } | ||
|
|
||
| func (impl *GitCliUtil) runCommand(cmd *exec.Cmd) (response, errMsg string, err error) { | ||
| cmd.Env = append(cmd.Env, "HOME=/dev/null") | ||
| outBytes, err := cmd.CombinedOutput() | ||
| if err != nil { | ||
| exErr, ok := err.(*exec.ExitError) | ||
| if !ok { | ||
| return "", "", err | ||
| } | ||
| errOutput := string(exErr.Stderr) | ||
| return "", errOutput, err | ||
| } | ||
| output := string(outBytes) | ||
| output = strings.TrimSpace(output) | ||
| return output, "", nil | ||
| } | ||
|
|
||
| func (impl *GitCliUtil) Init(rootDir string, remoteUrl string, isBare bool) error { | ||
| //----------------- | ||
| err := os.RemoveAll(rootDir) | ||
| if err != nil { | ||
| impl.logger.Errorw("error in cleaning rootDir", "err", err) | ||
| return err | ||
| } | ||
| err = os.MkdirAll(rootDir, 0755) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| repo, err := git.PlainInit(rootDir, isBare) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| _, err = repo.CreateRemote(&config.RemoteConfig{ | ||
| Name: git.DefaultRemoteName, | ||
| URLs: []string{remoteUrl}, | ||
| }) | ||
| return err | ||
| } | ||
|
|
||
| func (impl *GitCliUtil) Clone(rootDir string, remoteUrl string, username string, password string) (response, errMsg string, err error) { | ||
| err = impl.Init(rootDir, remoteUrl, false) | ||
| if err != nil { | ||
| return "", "", err | ||
| } | ||
| response, errMsg, err = impl.Fetch(rootDir, username, password) | ||
| if err == nil && errMsg == "" { | ||
| response, errMsg, err = impl.Pull(rootDir, username, password, "master") | ||
| } | ||
| return response, errMsg, err | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.