Skip to content

Commit

Permalink
Feat/next3 (#1635)
Browse files Browse the repository at this point in the history
* more next-backend functionality added
  • Loading branch information
motatoes authored Jul 25, 2024
1 parent b0838f2 commit ec35c77
Show file tree
Hide file tree
Showing 34 changed files with 2,174 additions and 771 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/next_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
push:
branches:
- develop # change to main if needed
- feat/next2
- feat/next3

jobs:
deploy:
Expand Down
31 changes: 31 additions & 0 deletions next/ci_backends/ci_backends.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ci_backends

import (
"github.com/diggerhq/digger/backend/utils"
"github.com/diggerhq/digger/libs/spec"
)

type CiBackend interface {
TriggerWorkflow(spec spec.Spec, runName string, vcsToken string) error
}

type JenkinsCi struct{}

type CiBackendOptions struct {
GithubClientProvider utils.GithubClientProvider
GithubInstallationId int64
GitlabProjectId int
GitlabmergeRequestEventName string
GitlabCIPipelineID string
GitlabCIPipelineIID int
GitlabCIMergeRequestID int
GitlabCIMergeRequestIID int
GitlabCIProjectName string
GitlabciprojectNamespace string
GitlabciprojectId int
GitlabciprojectNamespaceId int
GitlabDiscussionId string
RepoFullName string
RepoOwner string
RepoName string
}
32 changes: 32 additions & 0 deletions next/ci_backends/github_actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ci_backends

import (
"context"
"encoding/json"
orchestrator_scheduler "github.com/diggerhq/digger/libs/scheduler"
"github.com/diggerhq/digger/libs/spec"
"github.com/google/go-github/v61/github"
"log"
)

type GithubActionCi struct {
Client *github.Client
}

func (g GithubActionCi) TriggerWorkflow(spec spec.Spec, runName string, vcsToken string) error {
log.Printf("TriggerGithubWorkflow: repoOwner: %v, repoName: %v, commentId: %v", spec.VCS.RepoOwner, spec.VCS.RepoName, spec.CommentId)
client := g.Client
specBytes, err := json.Marshal(spec)

inputs := orchestrator_scheduler.WorkflowInput{
Spec: string(specBytes),
RunName: runName,
}

_, err = client.Actions.CreateWorkflowDispatchEventByFileName(context.Background(), spec.VCS.RepoOwner, spec.VCS.RepoName, spec.VCS.WorkflowFile, github.CreateWorkflowDispatchEventRequest{
Ref: spec.Job.Branch,
Inputs: inputs.ToMap(),
})

return err
}
1 change: 1 addition & 0 deletions next/ci_backends/jenkins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package ci_backends
25 changes: 25 additions & 0 deletions next/ci_backends/provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ci_backends

import (
"fmt"
"github.com/diggerhq/digger/next/utils"
"log"
)

type CiBackendProvider interface {
GetCiBackend(options CiBackendOptions) (CiBackend, error)
}

type DefaultBackendProvider struct{}

func (d DefaultBackendProvider) GetCiBackend(options CiBackendOptions) (CiBackend, error) {
client, _, err := utils.GetGithubClient(options.GithubClientProvider, options.GithubInstallationId, options.RepoFullName)
if err != nil {
log.Printf("GetCiBackend: could not get github client: %v", err)
return nil, fmt.Errorf("could not get github client: %v", err)
}
backend := &GithubActionCi{
Client: client,
}
return backend, nil
}
Loading

0 comments on commit ec35c77

Please sign in to comment.