fix: set repository name in jobs (#99412)

This commit is contained in:
Mariell Hoversholm authored and GitHub committed 2025-01-23 09:54:47 +01:00
1 parent eab86bb7d2
commit bfbc601579
4 files changed
+26 -15

No files matched your search

@@ -470,7 +470,8 @@ func (r *githubRepository) parsePushEvent(event *github.PushEvent) (*provisionin
return &provisioning.WebhookResponse{
Code: http.StatusAccepted,
Job: &provisioning.JobSpec{
Action: provisioning.JobActionSync,
Repository: r.Config().GetName(),
Action: provisioning.JobActionSync,
},
}, nil
}
@@ -519,11 +520,12 @@ func (r *githubRepository) parsePullRequestEvent(event *github.PullRequestEvent)
Code: http.StatusAccepted, // Nothing needed
Message: fmt.Sprintf("pull request: %s", action),
Job: &provisioning.JobSpec{
Action: provisioning.JobActionPullRequest,
URL: pr.GetHTMLURL(),
PR: pr.GetNumber(),
Ref: pr.GetHead().GetRef(),
Hash: pr.GetHead().GetSHA(),
Repository: r.Config().GetName(),
Action: provisioning.JobActionPullRequest,
URL: pr.GetHTMLURL(),
PR: pr.GetNumber(),
Ref: pr.GetHead().GetRef(),
Hash: pr.GetHead().GetSHA(),
},
}, nil
}
@@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
)
@@ -65,11 +66,12 @@ func TestParseWebhooks(t *testing.T) {
{"pull_request", "opened", provisioning.WebhookResponse{
Code: http.StatusAccepted, // 202
Job: &provisioning.JobSpec{
Action: provisioning.JobActionPullRequest,
Ref: "dashboard/1733653266690",
Hash: "ab5446a53df9e5f8bdeed52250f51fad08e822bc",
PR: 12,
URL: "https://github.com/grafana/git-ui-sync-demo/pull/12",
Repository: "unit-test-repo",
Action: provisioning.JobActionPullRequest,
Ref: "dashboard/1733653266690",
Hash: "ab5446a53df9e5f8bdeed52250f51fad08e822bc",
PR: 12,
URL: "https://github.com/grafana/git-ui-sync-demo/pull/12",
},
}},
{"push", "different_branch", provisioning.WebhookResponse{
@@ -78,13 +80,15 @@ func TestParseWebhooks(t *testing.T) {
{"push", "nothing_relevant", provisioning.WebhookResponse{
Code: http.StatusAccepted,
Job: &provisioning.JobSpec{ // we want to always push a sync job
Action: provisioning.JobActionSync,
Repository: "unit-test-repo",
Action: provisioning.JobActionSync,
},
}},
{"push", "nested", provisioning.WebhookResponse{
Code: http.StatusAccepted,
Job: &provisioning.JobSpec{
Action: provisioning.JobActionSync,
Repository: "unit-test-repo",
Action: provisioning.JobActionSync,
},
}},
{"issue_comment", "created", provisioning.WebhookResponse{
@@ -94,6 +98,9 @@ func TestParseWebhooks(t *testing.T) {
gh := &githubRepository{
config: &provisioning.Repository{
ObjectMeta: v1.ObjectMeta{
Name: "unit-test-repo",
},
Spec: provisioning.RepositorySpec{
GitHub: &provisioning.GitHubRepositoryConfig{
Repository: "git-ui-sync-demo",
@@ -346,7 +346,8 @@ func (r *localRepository) Webhook(ctx context.Context, req *http.Request) (*prov
return &provisioning.WebhookResponse{
Code: http.StatusAccepted,
Job: &provisioning.JobSpec{
Action: provisioning.JobActionSync, // sync the latest changes
Repository: r.Config().GetName(),
Action: provisioning.JobActionSync, // sync the latest changes
},
}, nil
}
@@ -349,7 +349,8 @@ func (rc *RepositoryController) process(item *queueItem) error {
},
},
Spec: provisioning.JobSpec{
Action: provisioning.JobActionSync,
Repository: cachedRepo.GetName(),
Action: provisioning.JobActionSync,
},
})
if err != nil {