-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from flanksource/git-check
feat: add support askgit
- Loading branch information
Showing
13 changed files
with
326 additions
and
2 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,66 @@ | ||
package checks | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
osExec "os/exec" | ||
"strings" | ||
|
||
"github.com/flanksource/canary-checker/api/context" | ||
"github.com/flanksource/canary-checker/api/external" | ||
v1 "github.com/flanksource/canary-checker/api/v1" | ||
"github.com/flanksource/canary-checker/pkg" | ||
) | ||
|
||
func init() { | ||
//register metrics here | ||
} | ||
|
||
type GitHubChecker struct { | ||
} | ||
|
||
func (c *GitHubChecker) Type() string { | ||
return "github" | ||
} | ||
|
||
func (c *GitHubChecker) Run(ctx *context.Context) []*pkg.CheckResult { | ||
var results []*pkg.CheckResult | ||
for _, conf := range ctx.Canary.Spec.GitHub { | ||
result := c.Check(ctx, conf) | ||
if result != nil { | ||
results = append(results, result) | ||
} | ||
} | ||
return results | ||
} | ||
|
||
func (c *GitHubChecker) Check(ctx *context.Context, extConfig external.Check) *pkg.CheckResult { | ||
check := extConfig.(v1.GitHubCheck) | ||
checkResult := pkg.Success(check, ctx.Canary) | ||
_, githubToken, err := ctx.Kommons.GetEnvValue(*check.GithubToken, ctx.Canary.GetNamespace()) | ||
if err != nil { | ||
return checkResult.Failf("error fetching github token: %v", err) | ||
} | ||
askGitCmd := fmt.Sprintf("GITHUB_TOKEN=%v askgit \"%v\" --format json", githubToken, check.Query) | ||
cmd := osExec.Command("bash", "-c", askGitCmd) | ||
output, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return checkResult.Failf("error executing askgit command: %v", err) | ||
} | ||
rows := string(output) | ||
var rowResults = make([]map[string]string, 0) | ||
for _, row := range strings.Split(rows, "\n") { | ||
if row == "" { | ||
continue | ||
} | ||
var rowResult map[string]string | ||
err := json.Unmarshal([]byte(row), &rowResult) | ||
if err != nil { | ||
return checkResult.Failf("error parsing askgit result: %v", err) | ||
} | ||
|
||
rowResults = append(rowResults, rowResult) | ||
} | ||
checkResult.AddDetails(rowResults) | ||
return checkResult | ||
} |
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,19 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
# Install askgit | ||
curl -L https://github.com/flanksource/askgit/releases/download/v0.4.8-flanksource/askgit-linux-amd64.tar.gz -o askgit.tar.gz | ||
tar xf askgit.tar.gz | ||
sudo mv askgit /usr/bin/askgit | ||
sudo chmod +x /usr/bin/askgit | ||
rm askgit.tar.gz | ||
|
||
#verification | ||
which askgit | ||
askgit --help | ||
|
||
# creating a GITHUB_TOKEN Secret | ||
kubectl create secret generic github-token --from-literal=GITHUB_TOKEN="${GH_TOKEN}" --namespace default | ||
|
||
kubectl get secret github-token -o yaml --namespace default |
Oops, something went wrong.