utils

package
v0.0.0-...-3a96d25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 30 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(key []byte, encodedCiphertext string) (string, error)

Decrypt decrypts a base64 encoded ciphertext using AES-256-GCM

func AESEncrypt

func AESEncrypt(key []byte, plaintext string) (string, error)

Encrypt encrypts a plaintext string using AES-256-GCM

func CloneGitRepoAndDoAction

func CloneGitRepoAndDoAction(repoUrl string, branch string, commitHash string, token string, action action) error

func CollapsedGraph

func CollapsedGraph(impactedParent *string, currentNode string, adjMap map[string]map[string]graph.Edge[string], g graph.Graph[string, configuration.Project], impactedProjects map[string]configuration.Project) error

func ConvertJobsToDiggerJobs

func ConvertJobsToDiggerJobs(jobType scheduler.DiggerCommand, vcsType models.DiggerVCSType, organisationId uint, jobsMap map[string]scheduler.Job, projectMap map[string]configuration.Project, projectsGraph graph.Graph[string, configuration.Project], githubInstallationId int64, branch string, prNumber int, repoOwner string, repoName string, repoFullName string, commitSha string, commentId int64, diggerConfigStr string, gitlabProjectId int) (*uuid.UUID, map[string]*models.DiggerJob, error)

ConvertJobsToDiggerJobs jobs is map with project name as a key and a Job as a value

func ExtractCleanRepoName

func ExtractCleanRepoName(gitlabURL string) (string, error)

func GenerateTerraformCode

func GenerateTerraformCode(appCode string, generationEndpoint string, webhookSecret string) (string, error)

func GetDiggerConfigForBranch

func GetDiggerConfigForBranch(gh GitlabProvider, projectId int, repoFullName string, repoOwner string, repoName string, cloneUrl string, branch string, prNumber int, discussionId string) (string, *dg_configuration.DiggerConfig, graph.Graph[string, dg_configuration.Project], error)

func GetGithubClient

func GetGithubClient(gh GithubClientProvider, installationId int64, repoFullName string) (*github.Client, *string, error)

func GetGithubClientFromAppId

func GetGithubClientFromAppId(gh GithubClientProvider, installationId int64, githubAppId int64, repoFullName string) (*github.Client, *string, error)

func GetGithubHostname

func GetGithubHostname() string

func GetGithubService

func GetGithubService(gh GithubClientProvider, installationId int64, repoFullName string, repoOwner string, repoName string) (*github2.GithubService, *string, error)

func GetGitlabService

func GetGitlabService(gh GitlabProvider, projectId int, repoName string, repoFullName string, prNumber int, discussionId string) (*orchestrator_gitlab.GitLabService, error)

func GetWorkflowIdAndUrlFromDiggerJobId

func GetWorkflowIdAndUrlFromDiggerJobId(client *github.Client, repoOwner string, repoName string, diggerJobID string) (int64, string, error)

func ImpactedProjectsOnlyGraph

func ImpactedProjectsOnlyGraph(projectsGraph graph.Graph[string, configuration.Project], impactedProjectMap map[string]configuration.Project) (graph.Graph[string, configuration.Project], error)

func IsInRepoAllowList

func IsInRepoAllowList(repoUrl string) bool

func ReportInitialJobsStatus

func ReportInitialJobsStatus(cr *CommentReporter, jobs []scheduler.Job) error

func ReportNoProjectsImpacted

func ReportNoProjectsImpacted(cr *CommentReporter, jobs []scheduler.Job) error

func SetPRStatusForJobs

func SetPRStatusForJobs(prService ci.PullRequestService, prNumber int, jobs []scheduler.Job) error

func TraverseGraphVisitAllParentsFirst

func TraverseGraphVisitAllParentsFirst(g graph.Graph[string, configuration.Project], visit func(value string) bool) error

func UpdateCRComment

func UpdateCRComment(cr *CommentReporter, comment string) error

Types

type CommentReporter

type CommentReporter struct {
	PrNumber  int
	PrService ci.PullRequestService
	CommentId string
}

func InitCommentReporter

func InitCommentReporter(prService ci.PullRequestService, prNumber int, commentMessage string) (*CommentReporter, error)

type CommentReporterManager

type CommentReporterManager struct {
	CommentReporter *CommentReporter
	// contains filtered or unexported fields
}

CommentReporterManager thin wrapper around CommentReporter that makes it "Lazy" so we dont comment anything when it is initialized and we can update comment at any time (intial update creates a new comment, future updates will update that comment)

func InitCommentReporterManager

func InitCommentReporterManager(prService ci.PullRequestService, prNumber int) CommentReporterManager

func (*CommentReporterManager) GetCommentReporter

func (cm *CommentReporterManager) GetCommentReporter() (*CommentReporter, error)

func (*CommentReporterManager) UpdateComment

func (cm *CommentReporterManager) UpdateComment(commentMessage string) (*CommentReporter, error)

type DecryptedGithubAppConnection

type DecryptedGithubAppConnection struct {
	GithubId         int64
	ClientID         string
	ClientSecret     string
	WebhookSecret    string
	PrivateKey       string
	PrivateKeyBase64 string
	Org              string
	Name             string
	GithubAppUrl     string
	OrganisationID   uint
}

represents a decrypted record

type DiggerGithubClientMockProvider

type DiggerGithubClientMockProvider struct {
	MockedHTTPClient *net.Client
}

func (DiggerGithubClientMockProvider) FetchCredentials

func (gh DiggerGithubClientMockProvider) FetchCredentials(githubAppId string) (string, string, string, string, error)

func (DiggerGithubClientMockProvider) Get

func (gh DiggerGithubClientMockProvider) Get(githubAppId int64, installationId int64) (*github.Client, *string, error)

func (DiggerGithubClientMockProvider) NewClient

func (gh DiggerGithubClientMockProvider) NewClient(netClient *net.Client) (*github.Client, error)

type DiggerGithubRealClientProvider

type DiggerGithubRealClientProvider struct {
}

just a wrapper around github client to be able to use mocks

func (DiggerGithubRealClientProvider) FetchCredentials

func (gh DiggerGithubRealClientProvider) FetchCredentials(githubAppId string) (string, string, string, string, error)

func (DiggerGithubRealClientProvider) Get

func (gh DiggerGithubRealClientProvider) Get(githubAppId int64, installationId int64) (*github.Client, *string, error)

func (DiggerGithubRealClientProvider) NewClient

func (gh DiggerGithubRealClientProvider) NewClient(netClient *net.Client) (*github.Client, error)

type GitAuth

type GitAuth struct {
	Username string
	Password string // Can be either password or access token
	Token    string // x-access-token
}

type GitShell

type GitShell struct {
	// contains filtered or unexported fields
}

func NewGitShell

func NewGitShell(workDir string, auth *GitAuth) *GitShell

func NewGitShellWithTokenAuth

func NewGitShellWithTokenAuth(workDir string, token string) *GitShell

func (*GitShell) Checkout

func (g *GitShell) Checkout(branchOrCommit string) error

func (*GitShell) Clone

func (g *GitShell) Clone(repoURL, branch string) error

Clone with authentication

type GithubClientProvider

type GithubClientProvider interface {
	NewClient(netClient *net.Client) (*github.Client, error)
	Get(githubAppId int64, installationId int64) (*github.Client, *string, error)
	FetchCredentials(githubAppId string) (string, string, string, string, error)
}

type GitlabClientProvider

type GitlabClientProvider struct{}

func (GitlabClientProvider) NewClient

func (g GitlabClientProvider) NewClient(token string) (*gitlab.Client, error)

type GitlabProvider

type GitlabProvider interface {
	NewClient(token string) (*gitlab.Client, error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL