Skip to content

Commit

Permalink
fix: add ability to generate Gitfile with https urls (#16)
Browse files Browse the repository at this point in the history
* fix: add ability to generate Gitfile with https urls

* Fix typo

* Fix typo

* Fix typo

* Fix typo

* Fix typo

* Fix typo

* Fix typo

* Fix typo
  • Loading branch information
isindir authored Jun 5, 2022
1 parent b1a6d7f commit 681be15
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 10 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ jobs:
run: |
make
- name: Slack Notification
uses: 8398a7/action-slack@v3
if: always()
with:
status: ${{ job.status }}
fields: repo,message # commit,author,action,eventName,ref,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}

release:
name: Release
runs-on: ubuntu-latest
Expand Down Expand Up @@ -81,3 +90,12 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}

- name: Slack Notification
uses: 8398a7/action-slack@v3
if: always()
with:
status: ${{ job.status }}
fields: repo,message # commit,author,action,eventName,ref,workflow,job,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Examples:

git-get config-gen -f Gitfile -p "gitlab" -u "[email protected]:johndoe" -t misc -l debug
git-get config-gen -f Gitfile -p "gitlab" -u "[email protected]:AcmeOrg" -t misc -l debug
git-get config-gen -f Gitfile -p "gitlab" -u "[email protected]:AcmeOrg/kube"
git-get config-gen -f Gitfile -p "gitlab" -u "[email protected]:AcmeOrg/kube" -g "https"
git-get config-gen -f Gitfile -p "bitbucket" -u "[email protected]:AcmeOrg" -t AcmeOrg
git-get config-gen -f Gitfile -p "github" -u "[email protected]:johndoe" -t johndoe -l debug
git-get config-gen -f Gitfile -p "github" -u "[email protected]:AcmeOrg" -t AcmeOrg -l debug
Expand All @@ -136,6 +136,7 @@ Flags:
-f, --config-file string Configuration file (default "~/Gitfile")
-p, --config-provider string Git provider name [gitlab|github|bitbucket] (default "gitlab")
-u, --config-url string Private URL prefix to construct Gitfile from (example: [email protected]:acmeorg), provider specific.
-g, --generate-url-of-type string Generate git URLs of type [ssh|https] (default "ssh")
--github-affiliation string Github: affiliation - comma-separated list of values.
Can include: owner, collaborator, or organization_member (default "owner,collaborator,organization_member")
--github-visibility string Github: visibility [all|public|private] (default "all")
Expand Down
16 changes: 14 additions & 2 deletions cmd/config_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ top level URL of the organisation organization, user or for Gitlab provider Grou
Example: `
git-get config-gen -f Gitfile -p "gitlab" -u "[email protected]:johndoe" -t misc -l debug
git-get config-gen -f Gitfile -p "gitlab" -u "[email protected]:AcmeOrg" -t misc -l debug
git-get config-gen -f Gitfile -p "gitlab" -u "[email protected]:AcmeOrg/kube"
git-get config-gen -f Gitfile -p "gitlab" -u "[email protected]:AcmeOrg/kube" -g "https"
git-get config-gen -f Gitfile -p "bitbucket" -u "[email protected]:AcmeOrg" -t AcmeOrg
git-get config-gen -f Gitfile -p "github" -u "[email protected]:johndoe" -t johndoe -l debug
git-get config-gen -f Gitfile -p "github" -u "[email protected]:AcmeOrg" -t AcmeOrg -l debug`,
Run: func(cmd *cobra.Command, args []string) {
initLogging(logLevel)
log.Debug("Generate Gitfile configuration file")
gitget.GenerateGitfileConfig(
cfgFile, ignoreFiles, gitCloudProviderRootURL, gitCloudProvider, targetClonePath, configGenParams)
cfgFile,
ignoreFiles,
gitCloudProviderRootURL,
gitCloudProvider,
targetClonePath,
configGenParams,
)
},
}

Expand Down Expand Up @@ -88,6 +94,12 @@ func init() {
"l",
"info",
"Logging level [debug|info|warn|error|fatal|panic]")
configGenCmd.Flags().StringVarP(
&configGenParams.GitSchema,
"generate-url-of-type",
"g",
"ssh",
"Generate git URLs of type [ssh|https]")
configGenCmd.Flags().StringVarP(
&gitCloudProvider,
"config-provider",
Expand Down
47 changes: 40 additions & 7 deletions gitget/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ var shellRunner = new(exec.ShellRunner)

// ConfigGenParamsStruct - data structure to store parameters passed via cli flags
type ConfigGenParamsStruct struct {
// ssh or https in output file
GitSchema string

// Gitlab specific vars
GitlabOwned bool
GitlabVisibility string
Expand Down Expand Up @@ -869,10 +872,23 @@ func fetchGithubRepos(
log.Debugf("%s: Number of fetched repositories: '%d'", repoSha, len(ghRepoList))

for repo := 0; repo < len(ghRepoList); repo++ {
gitGetRepoDefinition := Repo{
URL: *ghRepoList[repo].SSHURL,
Ref: *ghRepoList[repo].DefaultBranch,
var gitGetRepoDefinition Repo
switch configGenParams.GitSchema {
case "ssh":
gitGetRepoDefinition = Repo{
URL: *ghRepoList[repo].SSHURL,
Ref: *ghRepoList[repo].DefaultBranch,
}
case "https":
gitGetRepoDefinition = Repo{
URL: *ghRepoList[repo].HTMLURL,
Ref: *ghRepoList[repo].DefaultBranch,
}
default:
log.Fatalf("%s: Error: unknown '%s' git schema", repoSha, configGenParams.GitSchema)
os.Exit(1)
}

if targetClonePath != "" {
gitGetRepoDefinition.Path = targetClonePath
}
Expand All @@ -891,6 +907,7 @@ func getBitbucketRepositoryGitURL(
v map[string]interface{},
gitCloudProviderRootURL string,
fullName string,
GitSchema string,
) string {
var bbLinks []bitbucketLinks
cloneLinks := v["clone"]
Expand All @@ -913,7 +930,10 @@ func getBitbucketRepositoryGitURL(

for j := 0; j < len(bbLinks); j++ {
log.Debugf("%+v", bbLinks[j])
if bbLinks[j].Name == "ssh" {
if (bbLinks[j].Name == "ssh") && (GitSchema == "ssh") {
return bbLinks[j].HREF
}
if (bbLinks[j].Name == "https") && (GitSchema == "https") {
return bbLinks[j].HREF
}
}
Expand Down Expand Up @@ -942,6 +962,7 @@ func fetchBitbucketRepos(
bbRepoList[repo].Links,
gitCloudProviderRootURL,
bbRepoList[repo].Full_name,
configGenParams.GitSchema,
),
Ref: bbRepoList[repo].Mainbranch.Name,
}
Expand Down Expand Up @@ -986,9 +1007,21 @@ func fetchGitlabRepos(
for repo := 0; repo < len(glRepoList); repo++ {
log.Debugf("%s: '%s'", repoSha, glRepoList[repo].SSHURLToRepo)

gitGetRepoDefinition := Repo{
URL: glRepoList[repo].SSHURLToRepo,
Ref: glRepoList[repo].DefaultBranch,
var gitGetRepoDefinition Repo
switch configGenParams.GitSchema {
case "ssh":
gitGetRepoDefinition = Repo{
URL: glRepoList[repo].SSHURLToRepo,
Ref: glRepoList[repo].DefaultBranch,
}
case "https":
gitGetRepoDefinition = Repo{
URL: glRepoList[repo].HTTPURLToRepo,
Ref: glRepoList[repo].DefaultBranch,
}
default:
log.Fatalf("%s: Error: unknown '%s' git schema", repoSha, configGenParams.GitSchema)
os.Exit(1)
}
// MAYBE: CLI flag for with Namespace
if targetClonePath != "" {
Expand Down

0 comments on commit 681be15

Please sign in to comment.