-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also go fmt and validate on PR
- Loading branch information
Showing
11 changed files
with
173 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[*.go] | ||
ij_any_blank_lines_after_imports = 1 | ||
ij_go_add_parentheses_for_single_import = true | ||
ij_go_GROUP_CURRENT_PROJECT_IMPORTS = true | ||
ij_go_group_stdlib_imports = true | ||
ij_go_import_sorting = gofmt | ||
ij_go_move_all_imports_in_one_declaration = true | ||
ij_go_move_all_stdlib_imports_in_one_group = true | ||
ij_go_remove_redundant_import_aliases = true | ||
ij_go_use_back_quotes_for_imports = false |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
exitCode=0 | ||
message=$1 | ||
|
||
# Log the actual diff for debugging purposes | ||
git diff --name-only | cat | ||
if ! git diff --exit-code --quiet; then | ||
echo "$message" | ||
exitCode=1 | ||
fi | ||
|
||
exit $exitCode |
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
package gitlab_client | ||
|
||
import ( | ||
|
||
"github.com/rs/zerolog/log" | ||
"github.com/xanzy/go-gitlab" | ||
) | ||
|
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,70 @@ | ||
package validate | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"os/exec" | ||
"sync" | ||
|
||
"github.com/rs/zerolog/log" | ||
|
||
"github.com/zapier/kubechecks/pkg/repo" | ||
) | ||
|
||
type ReposDirectory struct { | ||
paths map[string]string | ||
|
||
mutex sync.Mutex | ||
} | ||
|
||
func newReposDirectory() *ReposDirectory { | ||
rd := &ReposDirectory{ | ||
paths: make(map[string]string), | ||
} | ||
|
||
return rd | ||
} | ||
|
||
func (rd *ReposDirectory) Register(ctx context.Context, cloneUrl string) string { | ||
var ( | ||
ok bool | ||
repoDir string | ||
) | ||
|
||
rd.mutex.Lock() | ||
defer rd.mutex.Unlock() | ||
|
||
repoDir, ok = rd.paths[cloneUrl] | ||
if ok { | ||
rd.fetchLatest() | ||
return repoDir | ||
} | ||
|
||
return rd.clone(ctx, cloneUrl) | ||
} | ||
|
||
func (rd *ReposDirectory) fetchLatest() { | ||
cmd := exec.Command("git", "pull") | ||
err := cmd.Run() | ||
if err != nil { | ||
log.Err(err).Msg("failed to pull latest") | ||
} | ||
} | ||
|
||
func (rd *ReposDirectory) clone(ctx context.Context, cloneUrl string) string { | ||
repoDir, err := os.MkdirTemp("/tmp", "schemas") | ||
if err != nil { | ||
log.Err(err).Msg("failed to make temp dir") | ||
return "" | ||
} | ||
|
||
r := repo.Repo{CloneURL: cloneUrl} | ||
err = r.CloneRepoLocal(ctx, repoDir) | ||
if err != nil { | ||
log.Err(err).Msg("failed to clone schemas repository") | ||
return "" | ||
} | ||
|
||
rd.paths[cloneUrl] = repoDir | ||
return repoDir | ||
} |
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
Oops, something went wrong.