Skip to content

Commit 7876ba4

Browse files
authored
Merge pull request #1 from mcncl/test/secretname_added
Test/secretname added
2 parents 0e9ea06 + 3c3561e commit 7876ba4

File tree

5 files changed

+27
-19
lines changed

5 files changed

+27
-19
lines changed

.buildkite/pipeline.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,3 @@ steps:
1919
run: golangci-lint
2020
tty: true
2121
mount-buildkite-agent: true
22-
- wait: ~
23-
24-
- label: "Test plugin"
25-
command: echo "Sweet plugin!"
26-
plugins:
27-
- ssh://git@github.com/mcncl/pr-commenter-buildkite-plugin: ~
28-

internal/repo/repo.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ import (
66
)
77

88
const (
9-
GitHubBaseURL = "https://github.com/"
10-
GitHubGitExt = ".git"
9+
GitHubBaseHTTPS = "https://github.com/"
10+
GitHubBaseSSH = "git@github.com:"
11+
GitHubGitExt = ".git"
1112
)
1213

1314
func ParseRepo(url string) (string, string, error) {
14-
path := strings.TrimPrefix(url, GitHubBaseURL)
15-
path = strings.TrimSuffix(path, GitHubGitExt)
15+
var path string
16+
if strings.HasPrefix(url, GitHubBaseHTTPS) {
17+
path = strings.TrimPrefix(url, GitHubBaseHTTPS)
18+
path = strings.TrimSuffix(path, GitHubGitExt)
19+
} else if strings.HasPrefix(url, GitHubBaseSSH) {
20+
path = strings.TrimPrefix(url, GitHubBaseSSH)
21+
path = strings.TrimSuffix(path, GitHubGitExt)
22+
} else {
23+
return "", "", fmt.Errorf("invalid repo URL format")
24+
}
1625

1726
parts := strings.Split(path, "/")
1827
if len(parts) != 2 {

internal/repo/repo_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ func TestParseRepoInfo(t *testing.T) {
2828
wantRepo: "",
2929
wantErr: true,
3030
},
31+
{
32+
name: "Valid GitHub SSH URL",
33+
repoURL: "git@github.com:mcncl/repo.git",
34+
wantOwner: "mcncl",
35+
wantRepo: "repo",
36+
wantErr: false,
37+
},
38+
{
39+
name: "Invalid GitHub SSH URL",
40+
repoURL: "git@github.com/mcncl/repo.git",
41+
wantOwner: "",
42+
wantRepo: "",
43+
wantErr: true,
44+
},
3145
}
3246

3347
for _, tt := range tests {

internal/secret/secret.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,13 @@ package secret
22

33
import (
44
"fmt"
5-
"os"
65
"os/exec"
76
"strings"
87
)
98

109
var ExecCommand = exec.Command
1110

1211
func GetSecret(name string) (string, error) {
13-
if name == "GITHUB_TOKEN" {
14-
_, found := os.LookupEnv(name)
15-
if !found {
16-
return "", fmt.Errorf("could not use %s, secret does not exist on cluster", name)
17-
}
18-
}
1912
cmd := ExecCommand("buildkite-agent", "secret", "get", name)
2013
output, err := cmd.Output()
2114
if err != nil {

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ func run() exitCode {
4646

4747
token, err := secret.GetSecret(secretName)
4848
if err != nil {
49-
fmt.Print(secretName)
5049
fmt.Fprintf(os.Stderr, "Error retrieving secret: %s\n", err)
5150
return exitError
5251
}

0 commit comments

Comments
 (0)