mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-23 08:56:29 +00:00
Rename forge-id to forge-remote-id (#1418)
This commit is contained in:
parent
d785d05718
commit
de8ea95dd3
31 changed files with 317 additions and 284 deletions
|
@ -102,7 +102,7 @@ func PostHook(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeRemoteID, tmpRepo.FullName)
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("failure to get repo %s from store", tmpRepo.FullName)
|
||||
log.Error().Err(err).Msg(msg)
|
||||
|
|
|
@ -87,7 +87,7 @@ func PostRepo(c *gin.Context) {
|
|||
sig,
|
||||
)
|
||||
|
||||
from, err := forge.Repo(c, user, repo.ForgeID, repo.Owner, repo.Name)
|
||||
from, err := forge.Repo(c, user, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err == nil {
|
||||
if repo.FullName != from.FullName {
|
||||
// create a redirection
|
||||
|
@ -260,7 +260,7 @@ func RepairRepo(c *gin.Context) {
|
|||
sig,
|
||||
)
|
||||
|
||||
from, err := forge.Repo(c, user, repo.ForgeID, repo.Owner, repo.Name)
|
||||
from, err := forge.Repo(c, user, repo.ForgeRemoteID, repo.Owner, repo.Name)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("get repo '%s/%s' from forge", repo.Owner, repo.Name)
|
||||
c.AbortWithStatus(http.StatusInternalServerError)
|
||||
|
|
|
@ -144,9 +144,9 @@ func (c *config) Teams(ctx context.Context, u *model.User) ([]*model.Team, error
|
|||
}
|
||||
|
||||
// Repo returns the named Bitbucket repository.
|
||||
func (c *config) Repo(ctx context.Context, u *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||
if id.IsValid() {
|
||||
name = string(id)
|
||||
func (c *config) Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||
if remoteID.IsValid() {
|
||||
name = string(remoteID)
|
||||
}
|
||||
repo, err := c.newClient(ctx, u).FindRepo(owner, name)
|
||||
if err != nil {
|
||||
|
|
|
@ -50,16 +50,16 @@ func convertStatus(status model.StatusValue) string {
|
|||
// structure to the common Woodpecker repository structure.
|
||||
func convertRepo(from *internal.Repo) *model.Repo {
|
||||
repo := model.Repo{
|
||||
ForgeID: model.ForgeID(from.UUID),
|
||||
Clone: cloneLink(from),
|
||||
Owner: strings.Split(from.FullName, "/")[0],
|
||||
Name: strings.Split(from.FullName, "/")[1],
|
||||
FullName: from.FullName,
|
||||
Link: from.Links.HTML.Href,
|
||||
IsSCMPrivate: from.IsPrivate,
|
||||
Avatar: from.Owner.Links.Avatar.Href,
|
||||
SCMKind: model.SCMKind(from.Scm),
|
||||
Branch: "master",
|
||||
ForgeRemoteID: model.ForgeRemoteID(from.UUID),
|
||||
Clone: cloneLink(from),
|
||||
Owner: strings.Split(from.FullName, "/")[0],
|
||||
Name: strings.Split(from.FullName, "/")[1],
|
||||
FullName: from.FullName,
|
||||
Link: from.Links.HTML.Href,
|
||||
IsSCMPrivate: from.IsPrivate,
|
||||
Avatar: from.Owner.Links.Avatar.Href,
|
||||
SCMKind: model.SCMKind(from.Scm),
|
||||
Branch: "master",
|
||||
}
|
||||
if repo.SCMKind == model.RepoHg {
|
||||
repo.Branch = "default"
|
||||
|
|
|
@ -153,7 +153,7 @@ func (*Config) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *Config) Repo(ctx context.Context, u *model.User, _ model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||
func (c *Config) Repo(ctx context.Context, u *model.User, _ model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||
repo, err := internal.NewClientWithToken(ctx, c.URL, c.Consumer, u.Token).FindRepo(owner, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -52,13 +52,13 @@ func convertStatus(status model.StatusValue) string {
|
|||
// structure to the common Woodpecker repository structure.
|
||||
func convertRepo(from *internal.Repo) *model.Repo {
|
||||
repo := model.Repo{
|
||||
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
||||
Name: from.Slug,
|
||||
Owner: from.Project.Key,
|
||||
Branch: "master",
|
||||
SCMKind: model.RepoGit,
|
||||
IsSCMPrivate: true, // Since we have to use Netrc it has to always be private :/
|
||||
FullName: fmt.Sprintf("%s/%s", from.Project.Key, from.Slug),
|
||||
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(from.ID)),
|
||||
Name: from.Slug,
|
||||
Owner: from.Project.Key,
|
||||
Branch: "master",
|
||||
SCMKind: model.RepoGit,
|
||||
IsSCMPrivate: true, // Since we have to use Netrc it has to always be private :/
|
||||
FullName: fmt.Sprintf("%s/%s", from.Project.Key, from.Slug),
|
||||
}
|
||||
|
||||
for _, item := range from.Links.Clone {
|
||||
|
|
|
@ -163,7 +163,7 @@ func (c *Coding) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
|||
}
|
||||
|
||||
// Repo fetches the repository from the forge.
|
||||
func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||
func (c *Coding) Repo(ctx context.Context, u *model.User, _ model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||
client := c.newClient(ctx, u)
|
||||
project, err := client.GetProject(owner, name)
|
||||
if err != nil {
|
||||
|
|
|
@ -45,7 +45,7 @@ type Forge interface {
|
|||
Teams(ctx context.Context, u *model.User) ([]*model.Team, error)
|
||||
|
||||
// Repo fetches the repository from the forge, preferred is using the ID, fallback is owner/name.
|
||||
Repo(ctx context.Context, u *model.User, id model.ForgeID, owner, name string) (*model.Repo, error)
|
||||
Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error)
|
||||
|
||||
// Repos fetches a list of repos from the forge.
|
||||
Repos(ctx context.Context, u *model.User) ([]*model.Repo, error)
|
|
@ -218,14 +218,14 @@ func (c *Gitea) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
|||
}
|
||||
|
||||
// Repo returns the Gitea repository.
|
||||
func (c *Gitea) Repo(ctx context.Context, u *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||
func (c *Gitea) Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||
client, err := c.newClientToken(ctx, u.Token)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if id.IsValid() {
|
||||
intID, err := strconv.ParseInt(string(id), 10, 64)
|
||||
if remoteID.IsValid() {
|
||||
intID, err := strconv.ParseInt(string(remoteID), 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -566,7 +566,7 @@ func (c *Gitea) getChangedFilesForPR(ctx context.Context, repo *model.Repo, inde
|
|||
return []string{}, nil
|
||||
}
|
||||
|
||||
repo, err := _store.GetRepoNameFallback(repo.ForgeID, repo.FullName)
|
||||
repo, err := _store.GetRepoNameFallback(repo.ForgeRemoteID, repo.FullName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ func Test_gitea(t *testing.T) {
|
|||
|
||||
g.Describe("Requesting a repository", func() {
|
||||
g.It("Should return the repository details", func() {
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeID, fakeRepo.Owner, fakeRepo.Name)
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeRemoteID, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||
|
@ -118,7 +118,7 @@ func Test_gitea(t *testing.T) {
|
|||
g.It("Should return the repository list", func() {
|
||||
repos, err := c.Repos(ctx, fakeUser)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repos[0].ForgeID).Equal(fakeRepo.ForgeID)
|
||||
g.Assert(repos[0].ForgeRemoteID).Equal(fakeRepo.ForgeRemoteID)
|
||||
g.Assert(repos[0].Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
||||
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||
|
@ -192,11 +192,11 @@ var (
|
|||
}
|
||||
|
||||
fakeRepo = &model.Repo{
|
||||
Clone: "http://gitea.com/test_name/repo_name.git",
|
||||
ForgeID: "5",
|
||||
Owner: "test_name",
|
||||
Name: "repo_name",
|
||||
FullName: "test_name/repo_name",
|
||||
Clone: "http://gitea.com/test_name/repo_name.git",
|
||||
ForgeRemoteID: "5",
|
||||
Owner: "test_name",
|
||||
Name: "repo_name",
|
||||
FullName: "test_name/repo_name",
|
||||
}
|
||||
|
||||
fakeRepoNotFound = &model.Repo{
|
||||
|
|
|
@ -37,16 +37,16 @@ func toRepo(from *gitea.Repository) *model.Repo {
|
|||
from.Owner.AvatarURL,
|
||||
)
|
||||
return &model.Repo{
|
||||
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
||||
SCMKind: model.RepoGit,
|
||||
Name: name,
|
||||
Owner: from.Owner.UserName,
|
||||
FullName: from.FullName,
|
||||
Avatar: avatar,
|
||||
Link: from.HTMLURL,
|
||||
IsSCMPrivate: from.Private || from.Owner.Visibility != gitea.VisibleTypePublic,
|
||||
Clone: from.CloneURL,
|
||||
Branch: from.DefaultBranch,
|
||||
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(from.ID)),
|
||||
SCMKind: model.RepoGit,
|
||||
Name: name,
|
||||
Owner: from.Owner.UserName,
|
||||
FullName: from.FullName,
|
||||
Avatar: avatar,
|
||||
Link: from.HTMLURL,
|
||||
IsSCMPrivate: from.Private || from.Owner.Visibility != gitea.VisibleTypePublic,
|
||||
Clone: from.CloneURL,
|
||||
Branch: from.DefaultBranch,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,17 +85,17 @@ func convertDesc(status model.StatusValue) string {
|
|||
// structure to the common Woodpecker repository structure.
|
||||
func convertRepo(from *github.Repository) *model.Repo {
|
||||
repo := &model.Repo{
|
||||
ForgeID: model.ForgeID(fmt.Sprint(from.GetID())),
|
||||
Name: from.GetName(),
|
||||
FullName: from.GetFullName(),
|
||||
Link: from.GetHTMLURL(),
|
||||
IsSCMPrivate: from.GetPrivate(),
|
||||
Clone: from.GetCloneURL(),
|
||||
Branch: from.GetDefaultBranch(),
|
||||
Owner: from.GetOwner().GetLogin(),
|
||||
Avatar: from.GetOwner().GetAvatarURL(),
|
||||
Perm: convertPerm(from.GetPermissions()),
|
||||
SCMKind: model.RepoGit,
|
||||
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(from.GetID())),
|
||||
Name: from.GetName(),
|
||||
FullName: from.GetFullName(),
|
||||
Link: from.GetHTMLURL(),
|
||||
IsSCMPrivate: from.GetPrivate(),
|
||||
Clone: from.GetCloneURL(),
|
||||
Branch: from.GetDefaultBranch(),
|
||||
Owner: from.GetOwner().GetLogin(),
|
||||
Avatar: from.GetOwner().GetAvatarURL(),
|
||||
Perm: convertPerm(from.GetPermissions()),
|
||||
SCMKind: model.RepoGit,
|
||||
}
|
||||
if len(repo.Branch) == 0 {
|
||||
repo.Branch = defaultBranch
|
||||
|
@ -146,15 +146,15 @@ func convertTeam(from *github.Organization) *model.Team {
|
|||
// from a webhook and convert to the common Woodpecker repository structure.
|
||||
func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
|
||||
repo := &model.Repo{
|
||||
ForgeID: model.ForgeID(fmt.Sprint(eventRepo.GetID())),
|
||||
Owner: eventRepo.GetOwner().GetLogin(),
|
||||
Name: eventRepo.GetName(),
|
||||
FullName: eventRepo.GetFullName(),
|
||||
Link: eventRepo.GetHTMLURL(),
|
||||
IsSCMPrivate: eventRepo.GetPrivate(),
|
||||
Clone: eventRepo.GetCloneURL(),
|
||||
Branch: eventRepo.GetDefaultBranch(),
|
||||
SCMKind: model.RepoGit,
|
||||
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(eventRepo.GetID())),
|
||||
Owner: eventRepo.GetOwner().GetLogin(),
|
||||
Name: eventRepo.GetName(),
|
||||
FullName: eventRepo.GetFullName(),
|
||||
Link: eventRepo.GetHTMLURL(),
|
||||
IsSCMPrivate: eventRepo.GetPrivate(),
|
||||
Clone: eventRepo.GetCloneURL(),
|
||||
Branch: eventRepo.GetDefaultBranch(),
|
||||
SCMKind: model.RepoGit,
|
||||
}
|
||||
if repo.Branch == "" {
|
||||
repo.Branch = defaultBranch
|
||||
|
|
|
@ -166,7 +166,7 @@ func (c *client) Teams(ctx context.Context, u *model.User) ([]*model.Team, error
|
|||
}
|
||||
|
||||
// Repo returns the GitHub repository.
|
||||
func (c *client) Repo(ctx context.Context, u *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||
func (c *client) Repo(ctx context.Context, u *model.User, id model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||
client := c.newClientToken(ctx, u.Token)
|
||||
|
||||
if id.IsValid() {
|
||||
|
@ -546,7 +546,7 @@ func (c *client) loadChangedFilesFromPullRequest(ctx context.Context, pull *gith
|
|||
return pipeline, nil
|
||||
}
|
||||
|
||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeRemoteID, tmpRepo.FullName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -78,9 +78,9 @@ func Test_github(t *testing.T) {
|
|||
|
||||
g.Describe("Requesting a repository", func() {
|
||||
g.It("Should return the repository details", func() {
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeID, fakeRepo.Owner, fakeRepo.Name)
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeRemoteID, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.ForgeID).Equal(fakeRepo.ForgeID)
|
||||
g.Assert(repo.ForgeRemoteID).Equal(fakeRepo.ForgeRemoteID)
|
||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
|
||||
|
@ -133,14 +133,14 @@ var (
|
|||
}
|
||||
|
||||
fakeRepo = &model.Repo{
|
||||
ForgeID: "5",
|
||||
Owner: "octocat",
|
||||
Name: "Hello-World",
|
||||
FullName: "octocat/Hello-World",
|
||||
Avatar: "https://github.com/images/error/octocat_happy.gif",
|
||||
Link: "https://github.com/octocat/Hello-World",
|
||||
Clone: "https://github.com/octocat/Hello-World.git",
|
||||
IsSCMPrivate: true,
|
||||
ForgeRemoteID: "5",
|
||||
Owner: "octocat",
|
||||
Name: "Hello-World",
|
||||
FullName: "octocat/Hello-World",
|
||||
Avatar: "https://github.com/images/error/octocat_happy.gif",
|
||||
Link: "https://github.com/octocat/Hello-World",
|
||||
Clone: "https://github.com/octocat/Hello-World.git",
|
||||
IsSCMPrivate: true,
|
||||
}
|
||||
|
||||
fakeRepoNotFound = &model.Repo{
|
||||
|
|
|
@ -37,16 +37,16 @@ func (g *GitLab) convertGitLabRepo(_repo *gitlab.Project) (*model.Repo, error) {
|
|||
owner := strings.Join(parts[:len(parts)-1], "/")
|
||||
name := parts[len(parts)-1]
|
||||
repo := &model.Repo{
|
||||
ForgeID: model.ForgeID(fmt.Sprint(_repo.ID)),
|
||||
Owner: owner,
|
||||
Name: name,
|
||||
FullName: _repo.PathWithNamespace,
|
||||
Avatar: _repo.AvatarURL,
|
||||
Link: _repo.WebURL,
|
||||
Clone: _repo.HTTPURLToRepo,
|
||||
Branch: _repo.DefaultBranch,
|
||||
Visibility: model.RepoVisibly(_repo.Visibility),
|
||||
IsSCMPrivate: !_repo.Public,
|
||||
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(_repo.ID)),
|
||||
Owner: owner,
|
||||
Name: name,
|
||||
FullName: _repo.PathWithNamespace,
|
||||
Avatar: _repo.AvatarURL,
|
||||
Link: _repo.WebURL,
|
||||
Clone: _repo.HTTPURLToRepo,
|
||||
Branch: _repo.DefaultBranch,
|
||||
Visibility: model.RepoVisibly(_repo.Visibility),
|
||||
IsSCMPrivate: !_repo.Public,
|
||||
}
|
||||
|
||||
if len(repo.Branch) == 0 { // TODO: do we need that?
|
||||
|
@ -88,7 +88,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, *
|
|||
repo.FullName = fmt.Sprintf("%s/%s", repo.Owner, repo.Name)
|
||||
}
|
||||
|
||||
repo.ForgeID = model.ForgeID(fmt.Sprint(obj.TargetProjectID))
|
||||
repo.ForgeRemoteID = model.ForgeRemoteID(fmt.Sprint(obj.TargetProjectID))
|
||||
repo.Link = target.WebURL
|
||||
|
||||
if target.GitHTTPURL != "" {
|
||||
|
@ -142,7 +142,7 @@ func convertPushHook(hook *gitlab.PushEvent) (*model.Repo, *model.Pipeline, erro
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
repo.ForgeID = model.ForgeID(fmt.Sprint(hook.ProjectID))
|
||||
repo.ForgeRemoteID = model.ForgeRemoteID(fmt.Sprint(hook.ProjectID))
|
||||
repo.Avatar = hook.Project.AvatarURL
|
||||
repo.Link = hook.Project.WebURL
|
||||
repo.Clone = hook.Project.GitHTTPURL
|
||||
|
@ -194,7 +194,7 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Pipeline, error)
|
|||
return nil, nil, err
|
||||
}
|
||||
|
||||
repo.ForgeID = model.ForgeID(fmt.Sprint(hook.ProjectID))
|
||||
repo.ForgeRemoteID = model.ForgeRemoteID(fmt.Sprint(hook.ProjectID))
|
||||
repo.Avatar = hook.Project.AvatarURL
|
||||
repo.Link = hook.Project.WebURL
|
||||
repo.Clone = hook.Project.GitHTTPURL
|
||||
|
|
|
@ -229,14 +229,14 @@ func (g *GitLab) getProject(ctx context.Context, client *gitlab.Client, owner, n
|
|||
}
|
||||
|
||||
// Repo fetches the repository from the forge.
|
||||
func (g *GitLab) Repo(ctx context.Context, user *model.User, id model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||
func (g *GitLab) Repo(ctx context.Context, user *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if id.IsValid() {
|
||||
intID, err := strconv.ParseInt(string(id), 10, 64)
|
||||
if remoteID.IsValid() {
|
||||
intID, err := strconv.ParseInt(string(remoteID), 10, 64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ func (g *GitLab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *
|
|||
return pipeline, nil
|
||||
}
|
||||
|
||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeRemoteID, tmpRepo.FullName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ func (c *client) Teams(ctx context.Context, u *model.User) ([]*model.Team, error
|
|||
}
|
||||
|
||||
// Repo returns the named Gogs repository.
|
||||
func (c *client) Repo(ctx context.Context, u *model.User, _ model.ForgeID, owner, name string) (*model.Repo, error) {
|
||||
func (c *client) Repo(ctx context.Context, u *model.User, _ model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||
client := c.newClientToken(u.Token)
|
||||
repo, err := client.GetRepo(owner, name)
|
||||
if err != nil {
|
||||
|
|
|
@ -86,7 +86,7 @@ func Test_gogs(t *testing.T) {
|
|||
|
||||
g.Describe("Requesting a repository", func() {
|
||||
g.It("Should return the repository details", func() {
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeID, fakeRepo.Owner, fakeRepo.Name)
|
||||
repo, err := c.Repo(ctx, fakeUser, fakeRepo.ForgeRemoteID, fakeRepo.Owner, fakeRepo.Name)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||
|
@ -119,7 +119,7 @@ func Test_gogs(t *testing.T) {
|
|||
g.It("Should return the repository list", func() {
|
||||
repos, err := c.Repos(ctx, fakeUser)
|
||||
g.Assert(err).IsNil()
|
||||
g.Assert(repos[0].ForgeID).Equal(fakeRepo.ForgeID)
|
||||
g.Assert(repos[0].ForgeRemoteID).Equal(fakeRepo.ForgeRemoteID)
|
||||
g.Assert(repos[0].Owner).Equal(fakeRepo.Owner)
|
||||
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
||||
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||
|
@ -183,11 +183,11 @@ var (
|
|||
}
|
||||
|
||||
fakeRepo = &model.Repo{
|
||||
ForgeID: "5",
|
||||
Clone: "http://gogs.com/test_name/repo_name.git",
|
||||
Owner: "test_name",
|
||||
Name: "repo_name",
|
||||
FullName: "test_name/repo_name",
|
||||
ForgeRemoteID: "5",
|
||||
Clone: "http://gogs.com/test_name/repo_name.git",
|
||||
Owner: "test_name",
|
||||
Name: "repo_name",
|
||||
FullName: "test_name/repo_name",
|
||||
}
|
||||
|
||||
fakeRepoNotFound = &model.Repo{
|
||||
|
|
|
@ -36,16 +36,16 @@ func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
|
|||
from.Owner.AvatarUrl,
|
||||
)
|
||||
return &model.Repo{
|
||||
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
||||
SCMKind: model.RepoGit,
|
||||
Name: name,
|
||||
Owner: from.Owner.UserName,
|
||||
FullName: from.FullName,
|
||||
Avatar: avatar,
|
||||
Link: from.HTMLURL,
|
||||
IsSCMPrivate: from.Private || privateMode,
|
||||
Clone: from.CloneURL,
|
||||
Branch: from.DefaultBranch,
|
||||
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(from.ID)),
|
||||
SCMKind: model.RepoGit,
|
||||
Name: name,
|
||||
Owner: from.Owner.UserName,
|
||||
FullName: from.FullName,
|
||||
Avatar: avatar,
|
||||
Link: from.HTMLURL,
|
||||
IsSCMPrivate: from.Private || privateMode,
|
||||
Clone: from.CloneURL,
|
||||
Branch: from.DefaultBranch,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -296,13 +296,13 @@ func (_m *Forge) Perm(ctx context.Context, u *model.User, r *model.Repo) (*model
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// Repo provides a mock function with given fields: ctx, u, id, owner, name
|
||||
func (_m *Forge) Repo(ctx context.Context, u *model.User, id model.ForgeID, owner string, name string) (*model.Repo, error) {
|
||||
ret := _m.Called(ctx, u, id, owner, name)
|
||||
// Repo provides a mock function with given fields: ctx, u, remoteID, owner, name
|
||||
func (_m *Forge) Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner string, name string) (*model.Repo, error) {
|
||||
ret := _m.Called(ctx, u, remoteID, owner, name)
|
||||
|
||||
var r0 *model.Repo
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *model.User, model.ForgeID, string, string) *model.Repo); ok {
|
||||
r0 = rf(ctx, u, id, owner, name)
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *model.User, model.ForgeRemoteID, string, string) *model.Repo); ok {
|
||||
r0 = rf(ctx, u, remoteID, owner, name)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Repo)
|
||||
|
@ -310,8 +310,8 @@ func (_m *Forge) Repo(ctx context.Context, u *model.User, id model.ForgeID, owne
|
|||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *model.User, model.ForgeID, string, string) error); ok {
|
||||
r1 = rf(ctx, u, id, owner, name)
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *model.User, model.ForgeRemoteID, string, string) error); ok {
|
||||
r1 = rf(ctx, u, remoteID, owner, name)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
|
|
@ -24,9 +24,10 @@ import (
|
|||
//
|
||||
// swagger:model repo
|
||||
type Repo struct {
|
||||
ID int64 `json:"id,omitempty" xorm:"pk autoincr 'repo_id'"`
|
||||
UserID int64 `json:"-" xorm:"repo_user_id"`
|
||||
ForgeID ForgeID `json:"-" xorm:"forge_id"`
|
||||
ID int64 `json:"id,omitempty" xorm:"pk autoincr 'repo_id'"`
|
||||
UserID int64 `json:"-" xorm:"repo_user_id"`
|
||||
// ForgeRemoteID is the unique identifier for the repository on the forge.
|
||||
ForgeRemoteID ForgeRemoteID `json:"-" xorm:"forge_remote_id"`
|
||||
Owner string `json:"owner" xorm:"UNIQUE(name) 'repo_owner'"`
|
||||
Name string `json:"name" xorm:"UNIQUE(name) 'repo_name'"`
|
||||
FullName string `json:"full_name" xorm:"UNIQUE 'repo_full_name'"`
|
||||
|
@ -75,8 +76,8 @@ func ParseRepo(str string) (user, repo string, err error) {
|
|||
|
||||
// Update updates the repository with values from the given Repo.
|
||||
func (r *Repo) Update(from *Repo) {
|
||||
if from.ForgeID.IsValid() {
|
||||
r.ForgeID = from.ForgeID
|
||||
if from.ForgeRemoteID.IsValid() {
|
||||
r.ForgeRemoteID = from.ForgeRemoteID
|
||||
}
|
||||
r.Owner = from.Owner
|
||||
r.Name = from.Name
|
||||
|
@ -109,8 +110,8 @@ type RepoPatch struct {
|
|||
CancelPreviousPipelineEvents *[]WebhookEvent `json:"cancel_previous_pipeline_events"`
|
||||
}
|
||||
|
||||
type ForgeID string
|
||||
type ForgeRemoteID string
|
||||
|
||||
func (r ForgeID) IsValid() bool {
|
||||
func (r ForgeRemoteID) IsValid() bool {
|
||||
return r != "" && r != "0"
|
||||
}
|
||||
|
|
|
@ -34,11 +34,11 @@ func TestGetPipelineQueue(t *testing.T) {
|
|||
assert.NoError(t, store.CreateUser(user))
|
||||
|
||||
repo1 := &model.Repo{
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
ForgeID: "1",
|
||||
IsActive: true,
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
ForgeRemoteID: "1",
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
assert.NoError(t, store.CreateRepo(repo1))
|
||||
|
@ -75,18 +75,18 @@ func TestUserFeed(t *testing.T) {
|
|||
assert.NoError(t, store.CreateUser(user))
|
||||
|
||||
repo1 := &model.Repo{
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test1",
|
||||
FullName: "bradrydzewski/test1",
|
||||
ForgeID: "1",
|
||||
IsActive: true,
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test1",
|
||||
FullName: "bradrydzewski/test1",
|
||||
ForgeRemoteID: "1",
|
||||
IsActive: true,
|
||||
}
|
||||
repo2 := &model.Repo{
|
||||
Owner: "johndoe",
|
||||
Name: "test",
|
||||
FullName: "johndoe/test2",
|
||||
ForgeID: "2",
|
||||
IsActive: true,
|
||||
Owner: "johndoe",
|
||||
Name: "test",
|
||||
FullName: "johndoe/test2",
|
||||
ForgeRemoteID: "2",
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
assert.NoError(t, store.CreateRepo(repo1))
|
||||
|
@ -126,25 +126,25 @@ func TestRepoListLatest(t *testing.T) {
|
|||
assert.NoError(t, store.CreateUser(user))
|
||||
|
||||
repo1 := &model.Repo{
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
ForgeID: "1",
|
||||
IsActive: true,
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
ForgeRemoteID: "1",
|
||||
IsActive: true,
|
||||
}
|
||||
repo2 := &model.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
FullName: "test/test",
|
||||
ForgeID: "2",
|
||||
IsActive: true,
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
FullName: "test/test",
|
||||
ForgeRemoteID: "2",
|
||||
IsActive: true,
|
||||
}
|
||||
repo3 := &model.Repo{
|
||||
Owner: "octocat",
|
||||
Name: "hello-world",
|
||||
FullName: "octocat/hello-world",
|
||||
ForgeID: "3",
|
||||
IsActive: true,
|
||||
Owner: "octocat",
|
||||
Name: "hello-world",
|
||||
FullName: "octocat/hello-world",
|
||||
ForgeRemoteID: "3",
|
||||
IsActive: true,
|
||||
}
|
||||
assert.NoError(t, store.CreateRepo(repo1))
|
||||
assert.NoError(t, store.CreateRepo(repo2))
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2022 Woodpecker Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
package migration
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
var renameForgeIDToForgeRemoteID = task{
|
||||
name: "rename-forge-id-to-forge-remote-id",
|
||||
required: true,
|
||||
fn: func(sess *xorm.Session) error {
|
||||
if err := renameColumn(sess, "repos", "forge_id", "forge_remote_id"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
|
@ -40,6 +40,7 @@ var migrationTasks = []*task{
|
|||
&renameColumnsBuildsToPipeline,
|
||||
&renameTableProcsToSteps,
|
||||
&renameRemoteToForge,
|
||||
&renameForgeIDToForgeRemoteID,
|
||||
}
|
||||
|
||||
var allBeans = []interface{}{
|
||||
|
|
|
@ -52,7 +52,7 @@ func (s storage) permUpsert(sess *xorm.Session, perm *model.Perm) error {
|
|||
|
||||
// lookup repo based on name or forge ID if possible
|
||||
if perm.RepoID == 0 && perm.Repo != nil {
|
||||
r, err := s.getRepoNameFallback(sess, perm.Repo.ForgeID, perm.Repo.FullName)
|
||||
r, err := s.getRepoNameFallback(sess, perm.Repo.ForgeRemoteID, perm.Repo.FullName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -28,11 +28,11 @@ func TestPermFind(t *testing.T) {
|
|||
|
||||
user := &model.User{ID: 1}
|
||||
repo := &model.Repo{
|
||||
UserID: 1,
|
||||
FullName: "bradrydzewski/test",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
ForgeID: "1",
|
||||
UserID: 1,
|
||||
FullName: "bradrydzewski/test",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
ForgeRemoteID: "1",
|
||||
}
|
||||
assert.NoError(t, store.CreateRepo(repo))
|
||||
|
||||
|
@ -73,11 +73,11 @@ func TestPermUpsert(t *testing.T) {
|
|||
|
||||
user := &model.User{ID: 1}
|
||||
repo := &model.Repo{
|
||||
UserID: 1,
|
||||
FullName: "bradrydzewski/test",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
ForgeID: "1",
|
||||
UserID: 1,
|
||||
FullName: "bradrydzewski/test",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
ForgeRemoteID: "1",
|
||||
}
|
||||
assert.NoError(t, store.CreateRepo(repo))
|
||||
|
||||
|
@ -153,11 +153,11 @@ func TestPermDelete(t *testing.T) {
|
|||
|
||||
user := &model.User{ID: 1}
|
||||
repo := &model.Repo{
|
||||
UserID: 1,
|
||||
FullName: "bradrydzewski/test",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
ForgeID: "1",
|
||||
UserID: 1,
|
||||
FullName: "bradrydzewski/test",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
ForgeRemoteID: "1",
|
||||
}
|
||||
assert.NoError(t, store.CreateRepo(repo))
|
||||
|
||||
|
|
|
@ -30,25 +30,25 @@ func (s storage) GetRepo(id int64) (*model.Repo, error) {
|
|||
return repo, wrapGet(s.engine.ID(id).Get(repo))
|
||||
}
|
||||
|
||||
func (s storage) GetRepoForgeID(id model.ForgeID) (*model.Repo, error) {
|
||||
func (s storage) GetRepoForgeID(remoteID model.ForgeRemoteID) (*model.Repo, error) {
|
||||
sess := s.engine.NewSession()
|
||||
defer sess.Close()
|
||||
return s.getRepoForgeID(sess, id)
|
||||
return s.getRepoForgeID(sess, remoteID)
|
||||
}
|
||||
|
||||
func (s storage) getRepoForgeID(e *xorm.Session, id model.ForgeID) (*model.Repo, error) {
|
||||
func (s storage) getRepoForgeID(e *xorm.Session, remoteID model.ForgeRemoteID) (*model.Repo, error) {
|
||||
repo := new(model.Repo)
|
||||
return repo, wrapGet(e.Where("forge_id = ?", id).Get(repo))
|
||||
return repo, wrapGet(e.Where("forge_remote_id = ?", remoteID).Get(repo))
|
||||
}
|
||||
|
||||
func (s storage) GetRepoNameFallback(forgeID model.ForgeID, fullName string) (*model.Repo, error) {
|
||||
func (s storage) GetRepoNameFallback(remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error) {
|
||||
sess := s.engine.NewSession()
|
||||
defer sess.Close()
|
||||
return s.getRepoNameFallback(sess, forgeID, fullName)
|
||||
return s.getRepoNameFallback(sess, remoteID, fullName)
|
||||
}
|
||||
|
||||
func (s storage) getRepoNameFallback(e *xorm.Session, forgeID model.ForgeID, fullName string) (*model.Repo, error) {
|
||||
repo, err := s.getRepoForgeID(e, forgeID)
|
||||
func (s storage) getRepoNameFallback(e *xorm.Session, remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error) {
|
||||
repo, err := s.getRepoForgeID(e, remoteID)
|
||||
if errors.Is(err, types.RecordNotExist) {
|
||||
return s.getRepoName(e, fullName)
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ func (s storage) RepoBatch(repos []*model.Repo) error {
|
|||
}
|
||||
|
||||
exist := true
|
||||
repo, err := s.getRepoNameFallback(sess, repos[i].ForgeID, repos[i].FullName)
|
||||
repo, err := s.getRepoNameFallback(sess, repos[i].ForgeRemoteID, repos[i].FullName)
|
||||
if err != nil {
|
||||
if errors.Is(err, types.RecordNotExist) {
|
||||
exist = false
|
||||
|
@ -186,9 +186,9 @@ func (s storage) RepoBatch(repos []*model.Repo) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
if repos[i].ForgeID.IsValid() {
|
||||
if repos[i].ForgeRemoteID.IsValid() {
|
||||
if _, err := sess.
|
||||
Where("forge_id = ?", repos[i].ForgeID).
|
||||
Where("forge_remote_id = ?", repos[i].ForgeRemoteID).
|
||||
Cols("repo_owner", "repo_name", "repo_full_name", "repo_scm", "repo_avatar", "repo_link", "repo_private", "repo_clone", "repo_branch", "forge_id").
|
||||
Update(repos[i]); err != nil {
|
||||
return err
|
||||
|
@ -204,7 +204,7 @@ func (s storage) RepoBatch(repos []*model.Repo) error {
|
|||
}
|
||||
|
||||
_, err := sess.
|
||||
Where("forge_id = ?", repos[i].ForgeID).
|
||||
Where("forge_remote_id = ?", repos[i].ForgeRemoteID).
|
||||
Get(repos[i])
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -136,22 +136,22 @@ func TestRepoList(t *testing.T) {
|
|||
assert.NoError(t, store.CreateUser(user))
|
||||
|
||||
repo1 := &model.Repo{
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
ForgeID: "1",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
ForgeRemoteID: "1",
|
||||
}
|
||||
repo2 := &model.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
FullName: "test/test",
|
||||
ForgeID: "2",
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
FullName: "test/test",
|
||||
ForgeRemoteID: "2",
|
||||
}
|
||||
repo3 := &model.Repo{
|
||||
Owner: "octocat",
|
||||
Name: "hello-world",
|
||||
FullName: "octocat/hello-world",
|
||||
ForgeID: "3",
|
||||
Owner: "octocat",
|
||||
Name: "hello-world",
|
||||
FullName: "octocat/hello-world",
|
||||
ForgeRemoteID: "3",
|
||||
}
|
||||
assert.NoError(t, store.CreateRepo(repo1))
|
||||
assert.NoError(t, store.CreateRepo(repo2))
|
||||
|
@ -192,28 +192,28 @@ func TestOwnedRepoList(t *testing.T) {
|
|||
assert.NoError(t, store.CreateUser(user))
|
||||
|
||||
repo1 := &model.Repo{
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
ForgeID: "1",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
ForgeRemoteID: "1",
|
||||
}
|
||||
repo2 := &model.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
FullName: "test/test",
|
||||
ForgeID: "2",
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
FullName: "test/test",
|
||||
ForgeRemoteID: "2",
|
||||
}
|
||||
repo3 := &model.Repo{
|
||||
Owner: "octocat",
|
||||
Name: "hello-world",
|
||||
FullName: "octocat/hello-world",
|
||||
ForgeID: "3",
|
||||
Owner: "octocat",
|
||||
Name: "hello-world",
|
||||
FullName: "octocat/hello-world",
|
||||
ForgeRemoteID: "3",
|
||||
}
|
||||
repo4 := &model.Repo{
|
||||
Owner: "demo",
|
||||
Name: "demo",
|
||||
FullName: "demo/demo",
|
||||
ForgeID: "4",
|
||||
Owner: "demo",
|
||||
Name: "demo",
|
||||
FullName: "demo/demo",
|
||||
ForgeRemoteID: "4",
|
||||
}
|
||||
assert.NoError(t, store.CreateRepo(repo1))
|
||||
assert.NoError(t, store.CreateRepo(repo2))
|
||||
|
@ -282,24 +282,24 @@ func TestRepoBatch(t *testing.T) {
|
|||
defer closer()
|
||||
|
||||
if !assert.NoError(t, store.CreateRepo(&model.Repo{
|
||||
ForgeID: "5",
|
||||
UserID: 1,
|
||||
FullName: "foo/bar",
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
IsActive: true,
|
||||
ForgeRemoteID: "5",
|
||||
UserID: 1,
|
||||
FullName: "foo/bar",
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
IsActive: true,
|
||||
})) {
|
||||
return
|
||||
}
|
||||
|
||||
repos := []*model.Repo{
|
||||
{
|
||||
ForgeID: "5",
|
||||
UserID: 1,
|
||||
FullName: "foo/bar",
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
IsActive: true,
|
||||
ForgeRemoteID: "5",
|
||||
UserID: 1,
|
||||
FullName: "foo/bar",
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
IsActive: true,
|
||||
Perm: &model.Perm{
|
||||
UserID: 1,
|
||||
Pull: true,
|
||||
|
@ -309,28 +309,28 @@ func TestRepoBatch(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
ForgeID: "6",
|
||||
UserID: 1,
|
||||
FullName: "bar/baz",
|
||||
Owner: "bar",
|
||||
Name: "baz",
|
||||
IsActive: true,
|
||||
ForgeRemoteID: "6",
|
||||
UserID: 1,
|
||||
FullName: "bar/baz",
|
||||
Owner: "bar",
|
||||
Name: "baz",
|
||||
IsActive: true,
|
||||
},
|
||||
{
|
||||
ForgeID: "7",
|
||||
UserID: 1,
|
||||
FullName: "baz/qux",
|
||||
Owner: "baz",
|
||||
Name: "qux",
|
||||
IsActive: true,
|
||||
ForgeRemoteID: "7",
|
||||
UserID: 1,
|
||||
FullName: "baz/qux",
|
||||
Owner: "baz",
|
||||
Name: "qux",
|
||||
IsActive: true,
|
||||
},
|
||||
{
|
||||
ForgeID: "8",
|
||||
UserID: 0, // not activated repos do hot have a user id assigned
|
||||
FullName: "baz/notes",
|
||||
Owner: "baz",
|
||||
Name: "notes",
|
||||
IsActive: false,
|
||||
ForgeRemoteID: "8",
|
||||
UserID: 0, // not activated repos do hot have a user id assigned
|
||||
FullName: "baz/notes",
|
||||
Owner: "baz",
|
||||
Name: "notes",
|
||||
IsActive: false,
|
||||
},
|
||||
}
|
||||
if !assert.NoError(t, store.RepoBatch(repos)) {
|
||||
|
@ -343,10 +343,10 @@ func TestRepoBatch(t *testing.T) {
|
|||
assert.True(t, perm.Admin)
|
||||
|
||||
repo := &model.Repo{
|
||||
ForgeID: "5",
|
||||
FullName: "foo/bar",
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
ForgeRemoteID: "5",
|
||||
FullName: "foo/bar",
|
||||
Owner: "foo",
|
||||
Name: "bar",
|
||||
Perm: &model.Perm{
|
||||
UserID: 1,
|
||||
Pull: true,
|
||||
|
@ -443,19 +443,19 @@ func TestRepoRedirection(t *testing.T) {
|
|||
defer closer()
|
||||
|
||||
repo := model.Repo{
|
||||
UserID: 1,
|
||||
ForgeID: "1",
|
||||
FullName: "bradrydzewski/test",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
UserID: 1,
|
||||
ForgeRemoteID: "1",
|
||||
FullName: "bradrydzewski/test",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
}
|
||||
assert.NoError(t, store.CreateRepo(&repo))
|
||||
|
||||
repoUpdated := model.Repo{
|
||||
ForgeID: "1",
|
||||
FullName: "bradrydzewski/test-renamed",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test-renamed",
|
||||
ForgeRemoteID: "1",
|
||||
FullName: "bradrydzewski/test-renamed",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test-renamed",
|
||||
}
|
||||
|
||||
assert.NoError(t, store.RepoBatch([]*model.Repo{&repoUpdated}))
|
||||
|
|
|
@ -192,25 +192,25 @@ func TestUsers(t *testing.T) {
|
|||
g.Assert(store.CreateUser(user)).IsNil()
|
||||
|
||||
repo1 := &model.Repo{
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
IsActive: true,
|
||||
ForgeID: "1",
|
||||
Owner: "bradrydzewski",
|
||||
Name: "test",
|
||||
FullName: "bradrydzewski/test",
|
||||
IsActive: true,
|
||||
ForgeRemoteID: "1",
|
||||
}
|
||||
repo2 := &model.Repo{
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
FullName: "test/test",
|
||||
IsActive: true,
|
||||
ForgeID: "2",
|
||||
Owner: "test",
|
||||
Name: "test",
|
||||
FullName: "test/test",
|
||||
IsActive: true,
|
||||
ForgeRemoteID: "2",
|
||||
}
|
||||
repo3 := &model.Repo{
|
||||
Owner: "octocat",
|
||||
Name: "hello-world",
|
||||
FullName: "octocat/hello-world",
|
||||
IsActive: true,
|
||||
ForgeID: "3",
|
||||
Owner: "octocat",
|
||||
Name: "hello-world",
|
||||
FullName: "octocat/hello-world",
|
||||
IsActive: true,
|
||||
ForgeRemoteID: "3",
|
||||
}
|
||||
g.Assert(store.CreateRepo(repo1)).IsNil()
|
||||
g.Assert(store.CreateRepo(repo2)).IsNil()
|
||||
|
|
|
@ -711,11 +711,11 @@ func (_m *Store) GetRepoCount() (int64, error) {
|
|||
}
|
||||
|
||||
// GetRepoForgeID provides a mock function with given fields: _a0
|
||||
func (_m *Store) GetRepoForgeID(_a0 model.ForgeID) (*model.Repo, error) {
|
||||
func (_m *Store) GetRepoForgeID(_a0 model.ForgeRemoteID) (*model.Repo, error) {
|
||||
ret := _m.Called(_a0)
|
||||
|
||||
var r0 *model.Repo
|
||||
if rf, ok := ret.Get(0).(func(model.ForgeID) *model.Repo); ok {
|
||||
if rf, ok := ret.Get(0).(func(model.ForgeRemoteID) *model.Repo); ok {
|
||||
r0 = rf(_a0)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
|
@ -724,7 +724,7 @@ func (_m *Store) GetRepoForgeID(_a0 model.ForgeID) (*model.Repo, error) {
|
|||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(model.ForgeID) error); ok {
|
||||
if rf, ok := ret.Get(1).(func(model.ForgeRemoteID) error); ok {
|
||||
r1 = rf(_a0)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
|
@ -756,13 +756,13 @@ func (_m *Store) GetRepoName(_a0 string) (*model.Repo, error) {
|
|||
return r0, r1
|
||||
}
|
||||
|
||||
// GetRepoNameFallback provides a mock function with given fields: forgeID, fullName
|
||||
func (_m *Store) GetRepoNameFallback(forgeID model.ForgeID, fullName string) (*model.Repo, error) {
|
||||
ret := _m.Called(forgeID, fullName)
|
||||
// GetRepoNameFallback provides a mock function with given fields: remoteID, fullName
|
||||
func (_m *Store) GetRepoNameFallback(remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error) {
|
||||
ret := _m.Called(remoteID, fullName)
|
||||
|
||||
var r0 *model.Repo
|
||||
if rf, ok := ret.Get(0).(func(model.ForgeID, string) *model.Repo); ok {
|
||||
r0 = rf(forgeID, fullName)
|
||||
if rf, ok := ret.Get(0).(func(model.ForgeRemoteID, string) *model.Repo); ok {
|
||||
r0 = rf(remoteID, fullName)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*model.Repo)
|
||||
|
@ -770,8 +770,8 @@ func (_m *Store) GetRepoNameFallback(forgeID model.ForgeID, fullName string) (*m
|
|||
}
|
||||
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(1).(func(model.ForgeID, string) error); ok {
|
||||
r1 = rf(forgeID, fullName)
|
||||
if rf, ok := ret.Get(1).(func(model.ForgeRemoteID, string) error); ok {
|
||||
r1 = rf(remoteID, fullName)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
|
|
@ -47,9 +47,9 @@ type Store interface {
|
|||
// GetRepo gets a repo by unique ID.
|
||||
GetRepo(int64) (*model.Repo, error)
|
||||
// GetRepoForgeID gets a repo by its forge ID.
|
||||
GetRepoForgeID(model.ForgeID) (*model.Repo, error)
|
||||
GetRepoForgeID(model.ForgeRemoteID) (*model.Repo, error)
|
||||
// GetRepoNameFallback gets the repo by its forge ID and if this doesn't exist by its full name.
|
||||
GetRepoNameFallback(forgeID model.ForgeID, fullName string) (*model.Repo, error)
|
||||
GetRepoNameFallback(remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error)
|
||||
// GetRepoName gets a repo by its full name.
|
||||
GetRepoName(string) (*model.Repo, error)
|
||||
// GetRepoCount gets a count of all repositories in the system.
|
||||
|
|
Loading…
Reference in a new issue