2025-05-20 09:40:15 +00:00
|
|
|
// Copyright 2025 Cloudbase Solutions SRL
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
|
// not use this file except in compliance with the License. You may obtain
|
|
|
|
|
// a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
|
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
|
// License for the specific language governing permissions and limitations
|
|
|
|
|
// under the License.
|
|
|
|
|
|
2022-07-07 16:48:00 +00:00
|
|
|
package common
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-04-06 16:18:42 +00:00
|
|
|
"net/url"
|
2022-07-07 16:48:00 +00:00
|
|
|
|
2025-06-17 21:03:46 +00:00
|
|
|
"github.com/google/go-github/v72/github"
|
2024-03-17 11:07:44 +00:00
|
|
|
|
|
|
|
|
"github.com/cloudbase/garm/params"
|
2022-07-07 16:48:00 +00:00
|
|
|
)
|
|
|
|
|
|
2024-03-17 10:21:41 +00:00
|
|
|
type GithubEntityOperations interface {
|
|
|
|
|
ListEntityHooks(ctx context.Context, opts *github.ListOptions) (ret []*github.Hook, response *github.Response, err error)
|
|
|
|
|
GetEntityHook(ctx context.Context, id int64) (ret *github.Hook, err error)
|
|
|
|
|
CreateEntityHook(ctx context.Context, hook *github.Hook) (ret *github.Hook, err error)
|
|
|
|
|
DeleteEntityHook(ctx context.Context, id int64) (ret *github.Response, err error)
|
|
|
|
|
PingEntityHook(ctx context.Context, id int64) (ret *github.Response, err error)
|
2025-04-28 13:19:27 +00:00
|
|
|
ListEntityRunners(ctx context.Context, opts *github.ListRunnersOptions) (*github.Runners, *github.Response, error)
|
2024-03-17 10:21:41 +00:00
|
|
|
ListEntityRunnerApplicationDownloads(ctx context.Context) ([]*github.RunnerApplicationDownload, *github.Response, error)
|
2025-04-27 19:34:44 +00:00
|
|
|
RemoveEntityRunner(ctx context.Context, runnerID int64) error
|
2025-04-28 13:37:33 +00:00
|
|
|
RateLimit(ctx context.Context) (*github.RateLimits, error)
|
2024-03-17 10:21:41 +00:00
|
|
|
CreateEntityRegistrationToken(ctx context.Context) (*github.RegistrationToken, *github.Response, error)
|
|
|
|
|
GetEntityJITConfig(ctx context.Context, instance string, pool params.Pool, labels []string) (jitConfigMap map[string]string, runner *github.Runner, err error)
|
2025-04-06 16:18:42 +00:00
|
|
|
|
|
|
|
|
// GetEntity returns the GitHub entity for which the github client was instanciated.
|
2025-05-12 21:47:13 +00:00
|
|
|
GetEntity() params.ForgeEntity
|
2025-04-06 16:18:42 +00:00
|
|
|
// GithubBaseURL returns the base URL for the github or GHES API.
|
|
|
|
|
GithubBaseURL() *url.URL
|
2023-08-15 17:19:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-01 13:35:56 +00:00
|
|
|
type RateLimitClient interface {
|
|
|
|
|
RateLimit(ctx context.Context) (*github.RateLimits, error)
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-07 16:48:00 +00:00
|
|
|
// GithubClient that describes the minimum list of functions we need to interact with github.
|
|
|
|
|
// Allows for easier testing.
|
2022-10-13 16:09:28 +00:00
|
|
|
//
|
2025-08-12 09:28:21 +00:00
|
|
|
//go:generate go run github.com/vektra/mockery/v2@latest
|
2022-07-07 16:48:00 +00:00
|
|
|
type GithubClient interface {
|
2024-03-17 10:21:41 +00:00
|
|
|
GithubEntityOperations
|
2023-08-15 17:19:06 +00:00
|
|
|
|
2022-09-20 14:25:52 +03:00
|
|
|
// GetWorkflowJobByID gets details about a single workflow job.
|
|
|
|
|
GetWorkflowJobByID(ctx context.Context, owner, repo string, jobID int64) (*github.WorkflowJob, *github.Response, error)
|
2022-10-13 16:09:28 +00:00
|
|
|
}
|