Skip to content

Commit ec35c77

Browse files
authored
Feat/next3 (#1635)
* more next-backend functionality added
1 parent b0838f2 commit ec35c77

34 files changed

+2174
-771
lines changed

.github/workflows/next_deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
push:
44
branches:
55
- develop # change to main if needed
6-
- feat/next2
6+
- feat/next3
77

88
jobs:
99
deploy:

next/ci_backends/ci_backends.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ci_backends
2+
3+
import (
4+
"github.com/diggerhq/digger/backend/utils"
5+
"github.com/diggerhq/digger/libs/spec"
6+
)
7+
8+
type CiBackend interface {
9+
TriggerWorkflow(spec spec.Spec, runName string, vcsToken string) error
10+
}
11+
12+
type JenkinsCi struct{}
13+
14+
type CiBackendOptions struct {
15+
GithubClientProvider utils.GithubClientProvider
16+
GithubInstallationId int64
17+
GitlabProjectId int
18+
GitlabmergeRequestEventName string
19+
GitlabCIPipelineID string
20+
GitlabCIPipelineIID int
21+
GitlabCIMergeRequestID int
22+
GitlabCIMergeRequestIID int
23+
GitlabCIProjectName string
24+
GitlabciprojectNamespace string
25+
GitlabciprojectId int
26+
GitlabciprojectNamespaceId int
27+
GitlabDiscussionId string
28+
RepoFullName string
29+
RepoOwner string
30+
RepoName string
31+
}

next/ci_backends/github_actions.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ci_backends
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
orchestrator_scheduler "github.com/diggerhq/digger/libs/scheduler"
7+
"github.com/diggerhq/digger/libs/spec"
8+
"github.com/google/go-github/v61/github"
9+
"log"
10+
)
11+
12+
type GithubActionCi struct {
13+
Client *github.Client
14+
}
15+
16+
func (g GithubActionCi) TriggerWorkflow(spec spec.Spec, runName string, vcsToken string) error {
17+
log.Printf("TriggerGithubWorkflow: repoOwner: %v, repoName: %v, commentId: %v", spec.VCS.RepoOwner, spec.VCS.RepoName, spec.CommentId)
18+
client := g.Client
19+
specBytes, err := json.Marshal(spec)
20+
21+
inputs := orchestrator_scheduler.WorkflowInput{
22+
Spec: string(specBytes),
23+
RunName: runName,
24+
}
25+
26+
_, err = client.Actions.CreateWorkflowDispatchEventByFileName(context.Background(), spec.VCS.RepoOwner, spec.VCS.RepoName, spec.VCS.WorkflowFile, github.CreateWorkflowDispatchEventRequest{
27+
Ref: spec.Job.Branch,
28+
Inputs: inputs.ToMap(),
29+
})
30+
31+
return err
32+
}

next/ci_backends/jenkins.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package ci_backends

next/ci_backends/provider.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package ci_backends
2+
3+
import (
4+
"fmt"
5+
"github.com/diggerhq/digger/next/utils"
6+
"log"
7+
)
8+
9+
type CiBackendProvider interface {
10+
GetCiBackend(options CiBackendOptions) (CiBackend, error)
11+
}
12+
13+
type DefaultBackendProvider struct{}
14+
15+
func (d DefaultBackendProvider) GetCiBackend(options CiBackendOptions) (CiBackend, error) {
16+
client, _, err := utils.GetGithubClient(options.GithubClientProvider, options.GithubInstallationId, options.RepoFullName)
17+
if err != nil {
18+
log.Printf("GetCiBackend: could not get github client: %v", err)
19+
return nil, fmt.Errorf("could not get github client: %v", err)
20+
}
21+
backend := &GithubActionCi{
22+
Client: client,
23+
}
24+
return backend, nil
25+
}

0 commit comments

Comments
 (0)