diff --git a/README.md b/README.md index ec20132..2d10429 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ to set up your token. Then create a secret using that token. ```bash -# First, copy your token to the clipboard. +# Before running the next command, copy your token to the clipboard. +# Then use pbpaste to paste that token into a file called "token". pbpaste > token kubectl create secret generic github-token --from-file=token -n argo rm token @@ -51,8 +52,8 @@ rm token Install: - kubectl apply -f github-executor-plugin-configmap.yaml + kubectl apply -n argo -f github-executor-plugin-configmap.yaml Uninstall: - kubectl delete cm github-executor-plugin + kubectl delete -n argo cm github-executor-plugin diff --git a/cmd/github-plugin/main.go b/cmd/github-plugin/main.go index 64a5aad..94a0396 100644 --- a/cmd/github-plugin/main.go +++ b/cmd/github-plugin/main.go @@ -24,7 +24,7 @@ func main() { ) tc := oauth2.NewClient(ctx, ts) client := github.NewClient(tc) - gitHubClient := &githubexecutor.GitHubClient{Issues: client.Issues} + gitHubClient := &githubexecutor.GitHubClient{Issues: client.Issues, Checks: client.Checks} executor := githubexecutor.NewGitHubExecutor(gitHubClient, string(agentToken)) http.HandleFunc("/api/v1/template.execute", githubexecutor.GitHubPlugin(&executor)) err = http.ListenAndServe(":4356", nil) diff --git a/internal/github_executor.go b/internal/github_executor.go index 9c57962..fa60673 100644 --- a/internal/github_executor.go +++ b/internal/github_executor.go @@ -82,6 +82,8 @@ func (e *GitHubExecutor) runAction(plugin *PluginSpec) (string, error) { var expectedResponseCode int if plugin.GitHub.Issue != nil { response, expectedResponseCode, err = e.runIssueAction(ctx, plugin.GitHub.Issue) + } else if plugin.GitHub.Check != nil { + response, expectedResponseCode, err = e.runCheckAction(ctx, plugin.GitHub.Check) } else { return "", fmt.Errorf("unsupported action") } @@ -121,6 +123,24 @@ func (e *GitHubExecutor) runIssueAction(ctx context.Context, issueAction *IssueA return nil, 0, fmt.Errorf("unsupported issue action") } +func (e *GitHubExecutor) runCheckAction(ctx context.Context, checkAction *CheckActionSpec) (*github.Response, int, error) { + if err := validateCheckAction(checkAction); err != nil { + return nil, 0, fmt.Errorf("failed to validate check action: %w", err) + } + _, response, err := e.client.Checks.CreateCheckRun(ctx, checkAction.Create.Owner, checkAction.Create.Repo, checkAction.Create.Request) + return response, 201, err +} + +func validateCheckAction(action *CheckActionSpec) error { + if action.Create == nil { + return err + } + if action.Create.Repo == "" { + return err + } + if action.Create. +} + func validateIssueAction(action *IssueActionSpec) error { if action.Comment == nil && action.Create == nil { return fmt.Errorf("the only available issue actions are 'comment' and 'create") diff --git a/internal/github_interface.go b/internal/github_interface.go index 3cbe997..0c0d697 100644 --- a/internal/github_interface.go +++ b/internal/github_interface.go @@ -8,9 +8,14 @@ import ( type GitHubClient struct { Issues GitHubIssuesClient + Checks GitHubChecksClient } type GitHubIssuesClient interface { CreateComment(ctx context.Context, owner, repo string, number int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error) Create(ctx context.Context, owner, repo string, issue *github.IssueRequest) (*github.Issue, *github.Response, error) } + +type GitHubChecksClient interface { + CreateCheckRun(ctx context.Context, owner, repo string, opt github.CreateCheckRunOptions) (*github.CheckRun, *github.Response, error) +} diff --git a/internal/types.go b/internal/types.go index 8a6bb33..4c0a7ef 100644 --- a/internal/types.go +++ b/internal/types.go @@ -9,6 +9,7 @@ type PluginSpec struct { type ActionSpec struct { Issue *IssueActionSpec `json:"issue,omitempty"` + Check *CheckActionSpec `json:"check,omitempty"` Timeout string `json:"timeout,omitempty"` } @@ -29,3 +30,13 @@ type IssueCreateAction struct { Repo string `json:"repo,omitempty"` Request *github.IssueRequest `json:"-"` } + +type CheckCreateAction struct { + Owner string `json:"owner,omitempty"` + Repo string `json:"repo,omitempty"` + Request github.CreateCheckRunOptions `json:"-"` +} + +type CheckActionSpec struct { + Create CheckCreateAction `json:"create,omitempty"` +} diff --git a/plugin.yaml b/plugin.yaml index dc341eb..73b7a40 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -29,6 +29,38 @@ metadata: number: "1" # PR number, from the owner: crenshaw-dev repo: github-executor-plugin + check: + create: + owner: # Required + repo: # Required + name: # Required + head_branch: # Optional + head_sha: # Optional + details_url: # Optional + external_id: # Optional + status: # Optional + conclusion: # Optional + started_at: # Optional + completed_at: # Optional + output: # Optional + title: + summary: + text: + annotations_count: + annotations_url: + annotations: + - filename: + blob_href: + start_line: + end_line: + warning_level: + message: + title: + raw_details: + images: + - alt: + image_url: + caption: ``` ## Prerequisites