2022-10-18 01:24:12 +00:00
|
|
|
// Copyright 2022 Woodpecker Authors
|
2018-02-19 22:24:10 +00:00
|
|
|
// Copyright 2018 Drone.IO Inc.
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// 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
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// 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-11-04 23:35:06 +00:00
|
|
|
package forge
|
2015-04-08 22:00:27 +00:00
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
//go:generate mockery --name Forge --output mocks --case underscore
|
2016-03-05 05:15:50 +00:00
|
|
|
|
2015-04-08 22:00:27 +00:00
|
|
|
import (
|
2021-09-28 10:56:59 +00:00
|
|
|
"context"
|
2015-04-08 22:00:27 +00:00
|
|
|
"net/http"
|
|
|
|
|
2023-12-08 07:15:08 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/server/forge/types"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
2015-04-08 22:00:27 +00:00
|
|
|
)
|
|
|
|
|
2021-09-27 21:32:08 +00:00
|
|
|
// TODO: use pagination
|
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
type Forge interface {
|
2022-06-17 18:14:01 +00:00
|
|
|
// Name returns the string name of this driver
|
|
|
|
Name() string
|
|
|
|
|
2023-05-31 16:30:41 +00:00
|
|
|
// URL returns the root url of a configured forge
|
|
|
|
URL() string
|
|
|
|
|
2015-04-08 22:00:27 +00:00
|
|
|
// Login authenticates the session and returns the
|
2024-02-13 15:19:02 +00:00
|
|
|
// forge user details and the URL to redirect to if not authorized yet.
|
|
|
|
Login(ctx context.Context, r *types.OAuthRequest) (*model.User, string, error)
|
2015-04-08 22:00:27 +00:00
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
// Auth authenticates the session and returns the forge user
|
2015-09-30 01:21:17 +00:00
|
|
|
// login for the given token and secret
|
2021-09-28 10:56:59 +00:00
|
|
|
Auth(ctx context.Context, token, secret string) (string, error)
|
2015-04-15 07:20:00 +00:00
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
// Teams fetches a list of team memberships from the forge.
|
2021-09-28 10:56:59 +00:00
|
|
|
Teams(ctx context.Context, u *model.User) ([]*model.Team, error)
|
2016-04-29 19:39:56 +00:00
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
// Repo fetches the repository from the forge, preferred is using the ID, fallback is owner/name.
|
2022-11-15 14:01:23 +00:00
|
|
|
Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error)
|
2015-09-30 01:21:17 +00:00
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
// Repos fetches a list of repos from the forge.
|
2021-09-28 10:56:59 +00:00
|
|
|
Repos(ctx context.Context, u *model.User) ([]*model.Repo, error)
|
2015-04-08 22:00:27 +00:00
|
|
|
|
2023-07-21 17:45:32 +00:00
|
|
|
// File fetches a file from the forge repository and returns it in string
|
2016-03-22 10:34:33 +00:00
|
|
|
// format.
|
2022-10-18 01:24:12 +00:00
|
|
|
File(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]byte, error)
|
2015-04-08 22:00:27 +00:00
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
// Dir fetches a folder from the forge repository
|
2022-11-06 11:44:04 +00:00
|
|
|
Dir(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, f string) ([]*types.FileMeta, error)
|
2019-06-03 07:16:15 +00:00
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
// Status sends the commit status to the forge.
|
2015-04-08 22:00:27 +00:00
|
|
|
// An example would be the GitHub pull request status.
|
2023-06-27 16:01:18 +00:00
|
|
|
Status(ctx context.Context, u *model.User, r *model.Repo, b *model.Pipeline, p *model.Workflow) error
|
2015-04-08 22:00:27 +00:00
|
|
|
|
2015-04-28 21:39:48 +00:00
|
|
|
// Netrc returns a .netrc file that can be used to clone
|
2022-11-04 23:35:06 +00:00
|
|
|
// private repositories from a forge.
|
2015-09-30 01:21:17 +00:00
|
|
|
Netrc(u *model.User, r *model.Repo) (*model.Netrc, error)
|
2015-04-28 21:39:48 +00:00
|
|
|
|
2016-05-01 06:22:30 +00:00
|
|
|
// Activate activates a repository by creating the post-commit hook.
|
2021-09-28 10:56:59 +00:00
|
|
|
Activate(ctx context.Context, u *model.User, r *model.Repo, link string) error
|
2015-04-08 22:00:27 +00:00
|
|
|
|
2016-05-01 06:22:30 +00:00
|
|
|
// Deactivate deactivates a repository by removing all previously created
|
|
|
|
// post-commit hooks matching the given link.
|
2021-09-28 10:56:59 +00:00
|
|
|
Deactivate(ctx context.Context, u *model.User, r *model.Repo, link string) error
|
2015-04-08 22:00:27 +00:00
|
|
|
|
2021-10-27 00:47:55 +00:00
|
|
|
// Branches returns the names of all branches for the named repository.
|
2023-04-30 01:40:13 +00:00
|
|
|
Branches(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]string, error)
|
2021-10-27 00:47:55 +00:00
|
|
|
|
2022-11-09 07:12:17 +00:00
|
|
|
// BranchHead returns the sha of the head (latest commit) of the specified branch
|
2024-02-11 09:44:50 +00:00
|
|
|
BranchHead(ctx context.Context, u *model.User, r *model.Repo, branch string) (*model.Commit, error)
|
2022-08-31 22:36:32 +00:00
|
|
|
|
2023-03-19 09:43:57 +00:00
|
|
|
// PullRequests returns all pull requests for the named repository.
|
2023-04-30 01:40:13 +00:00
|
|
|
PullRequests(ctx context.Context, u *model.User, r *model.Repo, p *model.ListOptions) ([]*model.PullRequest, error)
|
2023-03-19 09:43:57 +00:00
|
|
|
|
2016-04-29 19:39:56 +00:00
|
|
|
// Hook parses the post-commit hook from the Request body and returns the
|
|
|
|
// required data in a standard format.
|
2023-07-14 00:03:54 +00:00
|
|
|
Hook(ctx context.Context, r *http.Request) (repo *model.Repo, pipeline *model.Pipeline, err error)
|
2022-07-25 01:09:35 +00:00
|
|
|
|
|
|
|
// OrgMembership returns if user is member of organization and if user
|
|
|
|
// is admin/owner in that organization.
|
2023-07-21 17:45:32 +00:00
|
|
|
OrgMembership(ctx context.Context, u *model.User, org string) (*model.OrgPerm, error)
|
|
|
|
|
|
|
|
// Org fetches the organization from the forge by name. If the name is a user an org with type user is returned.
|
|
|
|
Org(ctx context.Context, u *model.User, org string) (*model.Org, error)
|
2015-04-08 22:00:27 +00:00
|
|
|
}
|