-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
325 changed files
with
83,874 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
# You usually don't want your secrets to be passed on command line | ||
api-token: 's3cr3t' |
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,20 @@ | ||
package nagios | ||
|
||
import "time" | ||
|
||
const ( | ||
GitlabGitProvider = "gitlab" | ||
GithubGitProvider = "github" | ||
) | ||
|
||
type ProbeConfig struct { | ||
APIEndpoint string `mapstructure:"api-endpoint"` | ||
Debug bool `mapstructure:"debug"` | ||
GitProvider string `mapstructure:"git-provider"` | ||
APIToken string `mapstructure:"api-token"` | ||
Project string `mapstructure:"project"` | ||
Timeout time.Duration `mapstructure:"timeout"` | ||
TargetBranch string `mapstructure:"target-branch"` | ||
WarningLastUpdateDelay time.Duration `mapstructure:"delay-warning-last-update"` | ||
CriticalLastUpdateDelay time.Duration `mapstructure:"delay-critical-last-update"` | ||
} |
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,48 @@ | ||
package nagios | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/xanzy/go-gitlab" | ||
) | ||
|
||
var ( | ||
// https://docs.gitlab.com/ee/api/merge_requests.html#list-project-merge-requests | ||
// opened, closed, locked, or merged. | ||
gitlabMergeRequestsOpenedState = "opened" | ||
) | ||
|
||
type gitlabProjectMRChecker struct { | ||
client *gitlab.Client | ||
} | ||
|
||
func newGitlabProjectMRChecker(endpoint, apiToken string) (*gitlabProjectMRChecker, error) { | ||
c, err := gitlab.NewClient(apiToken, gitlab.WithBaseURL(endpoint)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &gitlabProjectMRChecker{ | ||
client: c, | ||
}, nil | ||
} | ||
|
||
func (g gitlabProjectMRChecker) CheckMergeRequests(project string, targetBranch string) ([]MergeRequest, error) { | ||
var gmr []MergeRequest | ||
mr, _, err := g.client.MergeRequests.ListProjectMergeRequests(project, &gitlab.ListProjectMergeRequestsOptions{ | ||
State: &gitlabMergeRequestsOpenedState, | ||
TargetBranch: &targetBranch, | ||
}) | ||
if err != nil { | ||
return gmr, errors.Wrap(err, "listing project merge-requests") | ||
} | ||
|
||
for _, cmr := range mr { | ||
gmr = append(gmr, MergeRequest{ | ||
CreatedAt: *cmr.CreatedAt, | ||
UpdatedAt: *cmr.UpdatedAt, | ||
ID: *&cmr.ID, | ||
Title: cmr.Title, | ||
}) | ||
} | ||
|
||
return gmr, nil | ||
} |
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 @@ | ||
package nagios | ||
|
||
import "time" | ||
|
||
type MergeRequest struct { | ||
ID int | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
Title string | ||
} |
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,5 @@ | ||
package nagios | ||
|
||
type GitMergeRequestChecker interface { | ||
CheckMergeRequests(project string, targetBranch string) ([]MergeRequest, error) | ||
} |
Oops, something went wrong.