Skip to content

Commit

Permalink
[patch] 🍱 Publish pending status to PR in another repository (#141)
Browse files Browse the repository at this point in the history
* feat: publish pending status to PR in another repsitory

* fix: handle error in sending pending status

* fix: update mock config

* chore: switch condition for more readable

* chore: make swag, reuse variable
  • Loading branch information
sunny299 authored Oct 28, 2022
1 parent 9065397 commit 2689920
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 307 deletions.
8 changes: 6 additions & 2 deletions api/v1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,14 @@ type PullRequestBundle struct {
// Dependencies defines a list of components which are required to be deployed together with the main component
// +optional
Dependencies []string `json:"dependencies,omitempty"`
// GitRepository represents a string of git "<owner>/<repository>" e.g., agoda-com/samsahai
// GitRepository represents a string of git repository "<owner>/<repository>" e.g., agoda-com/samsahai
// used for publishing commit status
// +optional
GitRepository string `json:"gitRepository,omitempty"`
GitRepository string `json:"gitRepository,omitempty"`
// GitProjectID represents a git repository project id
// used for publishing test runner status to Gitlab
// +optional
GitProjectID string `json:"gitProjectID,omitempty"`
PullRequestExtraConfig `json:",inline"`
}

Expand Down
18 changes: 14 additions & 4 deletions config/crds/env.samsahai.io_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,14 @@ spec:
environment
type: string
type: object
gitProjectID:
description: GitProjectID represents a git repository project
id used for publishing test runner status to Gitlab
type: string
gitRepository:
description: GitRepository represents a string of git "<owner>/<repository>"
e.g., agoda-com/samsahai used for publishing commit status
description: GitRepository represents a string of git repository
"<owner>/<repository>" e.g., agoda-com/samsahai used for
publishing commit status
type: string
maxRetry:
description: MaxRetry defines max retry counts of pull request
Expand Down Expand Up @@ -1346,10 +1351,15 @@ spec:
deploying environment
type: string
type: object
gitProjectID:
description: GitProjectID represents a git repository
project id used for publishing test runner status
to Gitlab
type: string
gitRepository:
description: GitRepository represents a string of git
"<owner>/<repository>" e.g., agoda-com/samsahai used
for publishing commit status
repository "<owner>/<repository>" e.g., agoda-com/samsahai
used for publishing commit status
type: string
maxRetry:
description: MaxRetry defines max retry counts of pull
Expand Down
8 changes: 6 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2022-10-19 11:09:44.83837 +0700 +07 m=+0.333853050
// 2022-10-27 17:25:07.465703 +0700 +07 m=+0.264431515

package docs

Expand Down Expand Up @@ -1744,8 +1744,12 @@ var doc = `{
"type": "object",
"$ref": "#/definitions/v1.ConfigDeploy"
},
"gitProjectID": {
"description": "GitProjectID represents a git repository project id\nused for publishing test runner status to Gitlab\n+optional",
"type": "string"
},
"gitRepository": {
"description": "GitRepository represents a string of git \"\u003cowner\u003e/\u003crepository\u003e\" e.g., agoda-com/samsahai\nused for publishing commit status\n+optional",
"description": "GitRepository represents a string of git repository \"\u003cowner\u003e/\u003crepository\u003e\" e.g., agoda-com/samsahai\nused for publishing commit status\n+optional",
"type": "string"
},
"maxRetry": {
Expand Down
6 changes: 5 additions & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1723,8 +1723,12 @@
"type": "object",
"$ref": "#/definitions/v1.ConfigDeploy"
},
"gitProjectID": {
"description": "GitProjectID represents a git repository project id\nused for publishing test runner status to Gitlab\n+optional",
"type": "string"
},
"gitRepository": {
"description": "GitRepository represents a string of git \"\u003cowner\u003e/\u003crepository\u003e\" e.g., agoda-com/samsahai\nused for publishing commit status\n+optional",
"description": "GitRepository represents a string of git repository \"\u003cowner\u003e/\u003crepository\u003e\" e.g., agoda-com/samsahai\nused for publishing commit status\n+optional",
"type": "string"
},
"maxRetry": {
Expand Down
8 changes: 7 additions & 1 deletion docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,15 @@ definitions:
Deployment represents configuration about deploy
+optional
type: object
gitProjectID:
description: |-
GitProjectID represents a git repository project id
used for publishing test runner status to Gitlab
+optional
type: string
gitRepository:
description: |-
GitRepository represents a string of git "<owner>/<repository>" e.g., agoda-com/samsahai
GitRepository represents a string of git repository "<owner>/<repository>" e.g., agoda-com/samsahai
used for publishing commit status
+optional
type: string
Expand Down
4 changes: 2 additions & 2 deletions internal/reporter/gitlab/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ func (r *reporter) getGitlabProjectID(configCtrl internal.ConfigController, team

projectID := ""
for _, b := range conf.Status.Used.PullRequest.Bundles {
if b.Name == bundleName && b.Deployment != nil {
projectID = b.Deployment.TestRunner.Gitlab.ProjectID
if b.Name == bundleName {
projectID = b.GitProjectID
break
}
}
Expand Down
16 changes: 2 additions & 14 deletions internal/reporter/gitlab/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,7 @@ func (c *mockConfigCtrl) Get(configName string) (*s2hv1.Config, error) {
{
Name: "bundle-1",
GitRepository: "error",
Deployment: &s2hv1.ConfigDeploy{
TestRunner: &s2hv1.ConfigTestRunner{
Gitlab: &s2hv1.ConfigGitlab{
ProjectID: "error",
},
},
},
GitProjectID: "error",
},
},
},
Expand All @@ -206,13 +200,7 @@ func (c *mockConfigCtrl) Get(configName string) (*s2hv1.Config, error) {
{},
},
GitRepository: "samsahai/samsahai",
Deployment: &s2hv1.ConfigDeploy{
TestRunner: &s2hv1.ConfigTestRunner{
Gitlab: &s2hv1.ConfigGitlab{
ProjectID: "12345",
},
},
},
GitProjectID: "12345",
},
},
},
Expand Down
29 changes: 15 additions & 14 deletions internal/staging/start_testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@ func (c *controller) sendTestPendingResult(queue *s2hv1.Queue) error {
}

for retry := 0; retry <= sendTestPendingRetry; retry++ {
if _, err := c.s2hClient.RunPostPullRequestQueueTestRunnerTrigger(ctx, &samsahairpc.TeamWithPullRequest{
if _, err = c.s2hClient.RunPostPullRequestQueueTestRunnerTrigger(ctx, &samsahairpc.TeamWithPullRequest{
TeamName: c.teamName,
Namespace: internal.GenStagingNamespace(c.teamName),
BundleName: internal.GenPullRequestBundleName(queue.Spec.Name, queue.Spec.PRNumber),
}); err != nil {
logger.Error(err,
"cannot send pull request test runner pending status report, team: %s, component: %s, prNumber: %s",
"cannot send pull request test runner pending status report,",
"team", c.teamName, "component", queue.Spec.Name, "pr number", queue.Spec.PRNumber)
// set state, cannot send test pending status
queue.Status.SetCondition(
Expand All @@ -358,19 +358,20 @@ func (c *controller) sendTestPendingResult(queue *s2hv1.Queue) error {
if err := c.updateQueue(queue); err != nil {
logger.Error(err, "cannot update queue", "name", queue.Name)
}
continue
}
logger.Info("sent pull request test runner pending status successfully",
"team", c.teamName, "component", queue.Spec.Name, "pr number", queue.Spec.PRNumber)
// set state, test pending status has been sent
queue.Status.SetCondition(
s2hv1.QueueTestPendingStatusSent,
v1.ConditionTrue,
"queue test pending status has been sent")
if err = c.updateQueue(queue); err != nil {
logger.Error(err, "cannot update queue", "name", queue.Name)
return err
}
break
}
logger.Info("sent pull request test runner pending status successfully",
"team", c.teamName, "component", queue.Spec.Name, "pr number", queue.Spec.PRNumber)
// set state, test pending status has been sent
queue.Status.SetCondition(
s2hv1.QueueTestPendingStatusSent,
v1.ConditionTrue,
"queue test pending status has been sent")
if err := c.updateQueue(queue); err != nil {
logger.Error(err, "cannot update queue", "name", queue.Name)
return err
}
return nil
return err
}
4 changes: 2 additions & 2 deletions internal/util/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ func (c *Client) PublishCommitStatus(repository, commitSHA, labelName, targetURL
return s2herrors.ErrRequestTimeout
case err := <-errCh:
logger.Error(err, "cannot publish commit status",
"repository", repository, "commitSHA", commitSHA)
"repository", repository, "commitSHA", commitSHA, "status", status)
return err
case <-resCh:
logger.Info("commit status successfully published to gitlab",
"repository", repository, "commitSHA", commitSHA)
"repository", repository, "commitSHA", commitSHA, "status", status)
return nil
}
}
Expand Down
Loading

0 comments on commit 2689920

Please sign in to comment.