Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pkg/pipelineascode/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ func (p *PacRun) verifyRepoAndUser(ctx context.Context) (*v1alpha1.Repository, e
}
// When /ok-to-test is approved, update the parent "Pipelines as Code CI" status to success
// to indicate the approval was successful before pipelines start running.
if p.event.EventType == opscomments.OkToTestCommentEventType.String() && !strings.Contains(p.vcx.GetConfig().Name, "github") {
// we only do this for all providers except github apps since github apps use the checkRun API to update the status
// checking installationID is <= 0 because sometime it's set to -1
if p.event.EventType == opscomments.OkToTestCommentEventType.String() && p.event.InstallationID <= 0 {
approvalStatus := providerstatus.StatusOpts{
Status: CompletedStatus,
Title: "Approved",
Expand Down
45 changes: 43 additions & 2 deletions pkg/pipelineascode/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -752,6 +754,36 @@ func TestVerifyRepoAndUser(t *testing.T) {
wantRepoNil: false,
wantErr: false,
},
{
name: "happy path with ok-to-test comment status reporting",
runevent: info.Event{
Organization: "owner",
Repository: "repo",
URL: "https://example.com/owner/repo",
SHA: "123abc",
EventType: opscomments.OkToTestCommentEventType.String(),
TriggerTarget: triggertype.PullRequest,
Sender: "owner",
Request: request,
},
repositories: []*v1alpha1.Repository{{
ObjectMeta: metav1.ObjectMeta{Name: "repo", Namespace: "ns"},
Spec: v1alpha1.RepositorySpec{
URL: "https://example.com/owner/repo",
GitProvider: &v1alpha1.GitProvider{
Secret: &v1alpha1.Secret{
Name: "secret",
},
WebhookSecret: &v1alpha1.Secret{
Name: "webhook-secret",
},
},
},
}},
webhookSecret: "secret",
wantRepoNil: false,
wantErr: false,
},
}

pacInfo := &info.PacOpts{Settings: settings.DefaultSettings()}
Expand Down Expand Up @@ -786,14 +818,23 @@ func TestVerifyRepoAndUser(t *testing.T) {
// status endpoint stub (used when CreateStatus is called)
mux.HandleFunc(
fmt.Sprintf("/repos/%s/%s/statuses/%s", tt.runevent.Organization, tt.runevent.Repository, tt.runevent.SHA),
func(rw http.ResponseWriter, _ *http.Request) { fmt.Fprint(rw, `{}`) },
func(rw http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(r.Body)
a := struct {
State string `json:"state"`
}{}
err := json.Unmarshal(body, &a)
assert.NilError(t, err)
assert.Equal(t, a.State, "success")
fmt.Fprint(rw, `{}`)
},
)

vcx := &ghprovider.Provider{Token: github.Ptr("token"), Logger: logger}
vcx.SetGithubClient(ghClient)
vcx.SetPacInfo(pacInfo)

k8int := &kitesthelper.KinterfaceTest{GetSecretResult: map[string]string{"pipelines-as-code-secret": tt.webhookSecret}}
k8int := &kitesthelper.KinterfaceTest{GetSecretResult: map[string]string{"pipelines-as-code-secret": tt.webhookSecret, "secret": "token", "webhook-secret": "secret"}}

stdata, _ := testclient.SeedTestData(t, ctx, testclient.Data{Repositories: tt.repositories /*Secret: []*corev1.Secret{secret}*/})
in := info.NewInfo()
Expand Down
Loading