mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeRemoteID, tmpRepo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("failure to get repo %s from store", tmpRepo.FullName)
|
msg := fmt.Sprintf("failure to get repo %s from store", tmpRepo.FullName)
|
||||||
log.Error().Err(err).Msg(msg)
|
log.Error().Err(err).Msg(msg)
|
||||||
|
|
|
@ -87,7 +87,7 @@ func PostRepo(c *gin.Context) {
|
||||||
sig,
|
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 err == nil {
|
||||||
if repo.FullName != from.FullName {
|
if repo.FullName != from.FullName {
|
||||||
// create a redirection
|
// create a redirection
|
||||||
|
@ -260,7 +260,7 @@ func RepairRepo(c *gin.Context) {
|
||||||
sig,
|
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 err != nil {
|
||||||
log.Error().Err(err).Msgf("get repo '%s/%s' from forge", repo.Owner, repo.Name)
|
log.Error().Err(err).Msgf("get repo '%s/%s' from forge", repo.Owner, repo.Name)
|
||||||
c.AbortWithStatus(http.StatusInternalServerError)
|
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.
|
// 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) {
|
func (c *config) Repo(ctx context.Context, u *model.User, remoteID model.ForgeRemoteID, owner, name string) (*model.Repo, error) {
|
||||||
if id.IsValid() {
|
if remoteID.IsValid() {
|
||||||
name = string(id)
|
name = string(remoteID)
|
||||||
}
|
}
|
||||||
repo, err := c.newClient(ctx, u).FindRepo(owner, name)
|
repo, err := c.newClient(ctx, u).FindRepo(owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func convertStatus(status model.StatusValue) string {
|
||||||
// structure to the common Woodpecker repository structure.
|
// structure to the common Woodpecker repository structure.
|
||||||
func convertRepo(from *internal.Repo) *model.Repo {
|
func convertRepo(from *internal.Repo) *model.Repo {
|
||||||
repo := model.Repo{
|
repo := model.Repo{
|
||||||
ForgeID: model.ForgeID(from.UUID),
|
ForgeRemoteID: model.ForgeRemoteID(from.UUID),
|
||||||
Clone: cloneLink(from),
|
Clone: cloneLink(from),
|
||||||
Owner: strings.Split(from.FullName, "/")[0],
|
Owner: strings.Split(from.FullName, "/")[0],
|
||||||
Name: strings.Split(from.FullName, "/")[1],
|
Name: strings.Split(from.FullName, "/")[1],
|
||||||
|
|
|
@ -153,7 +153,7 @@ func (*Config) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
||||||
return nil, nil
|
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)
|
repo, err := internal.NewClientWithToken(ctx, c.URL, c.Consumer, u.Token).FindRepo(owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -52,7 +52,7 @@ func convertStatus(status model.StatusValue) string {
|
||||||
// structure to the common Woodpecker repository structure.
|
// structure to the common Woodpecker repository structure.
|
||||||
func convertRepo(from *internal.Repo) *model.Repo {
|
func convertRepo(from *internal.Repo) *model.Repo {
|
||||||
repo := model.Repo{
|
repo := model.Repo{
|
||||||
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(from.ID)),
|
||||||
Name: from.Slug,
|
Name: from.Slug,
|
||||||
Owner: from.Project.Key,
|
Owner: from.Project.Key,
|
||||||
Branch: "master",
|
Branch: "master",
|
||||||
|
|
|
@ -163,7 +163,7 @@ func (c *Coding) TeamPerm(u *model.User, org string) (*model.Perm, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo fetches the repository from the forge.
|
// 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)
|
client := c.newClient(ctx, u)
|
||||||
project, err := client.GetProject(owner, name)
|
project, err := client.GetProject(owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -45,7 +45,7 @@ type Forge interface {
|
||||||
Teams(ctx context.Context, u *model.User) ([]*model.Team, error)
|
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 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 fetches a list of repos from the forge.
|
||||||
Repos(ctx context.Context, u *model.User) ([]*model.Repo, error)
|
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.
|
// 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)
|
client, err := c.newClientToken(ctx, u.Token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if id.IsValid() {
|
if remoteID.IsValid() {
|
||||||
intID, err := strconv.ParseInt(string(id), 10, 64)
|
intID, err := strconv.ParseInt(string(remoteID), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -566,7 +566,7 @@ func (c *Gitea) getChangedFilesForPR(ctx context.Context, repo *model.Repo, inde
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := _store.GetRepoNameFallback(repo.ForgeID, repo.FullName)
|
repo, err := _store.GetRepoNameFallback(repo.ForgeRemoteID, repo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,7 @@ func Test_gitea(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("Requesting a repository", func() {
|
g.Describe("Requesting a repository", func() {
|
||||||
g.It("Should return the repository details", 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(err).IsNil()
|
||||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
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() {
|
g.It("Should return the repository list", func() {
|
||||||
repos, err := c.Repos(ctx, fakeUser)
|
repos, err := c.Repos(ctx, fakeUser)
|
||||||
g.Assert(err).IsNil()
|
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].Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
||||||
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||||
|
@ -193,7 +193,7 @@ var (
|
||||||
|
|
||||||
fakeRepo = &model.Repo{
|
fakeRepo = &model.Repo{
|
||||||
Clone: "http://gitea.com/test_name/repo_name.git",
|
Clone: "http://gitea.com/test_name/repo_name.git",
|
||||||
ForgeID: "5",
|
ForgeRemoteID: "5",
|
||||||
Owner: "test_name",
|
Owner: "test_name",
|
||||||
Name: "repo_name",
|
Name: "repo_name",
|
||||||
FullName: "test_name/repo_name",
|
FullName: "test_name/repo_name",
|
||||||
|
|
|
@ -37,7 +37,7 @@ func toRepo(from *gitea.Repository) *model.Repo {
|
||||||
from.Owner.AvatarURL,
|
from.Owner.AvatarURL,
|
||||||
)
|
)
|
||||||
return &model.Repo{
|
return &model.Repo{
|
||||||
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(from.ID)),
|
||||||
SCMKind: model.RepoGit,
|
SCMKind: model.RepoGit,
|
||||||
Name: name,
|
Name: name,
|
||||||
Owner: from.Owner.UserName,
|
Owner: from.Owner.UserName,
|
||||||
|
|
|
@ -85,7 +85,7 @@ func convertDesc(status model.StatusValue) string {
|
||||||
// structure to the common Woodpecker repository structure.
|
// structure to the common Woodpecker repository structure.
|
||||||
func convertRepo(from *github.Repository) *model.Repo {
|
func convertRepo(from *github.Repository) *model.Repo {
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
ForgeID: model.ForgeID(fmt.Sprint(from.GetID())),
|
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(from.GetID())),
|
||||||
Name: from.GetName(),
|
Name: from.GetName(),
|
||||||
FullName: from.GetFullName(),
|
FullName: from.GetFullName(),
|
||||||
Link: from.GetHTMLURL(),
|
Link: from.GetHTMLURL(),
|
||||||
|
@ -146,7 +146,7 @@ func convertTeam(from *github.Organization) *model.Team {
|
||||||
// from a webhook and convert to the common Woodpecker repository structure.
|
// from a webhook and convert to the common Woodpecker repository structure.
|
||||||
func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
|
func convertRepoHook(eventRepo *github.PushEventRepository) *model.Repo {
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
ForgeID: model.ForgeID(fmt.Sprint(eventRepo.GetID())),
|
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(eventRepo.GetID())),
|
||||||
Owner: eventRepo.GetOwner().GetLogin(),
|
Owner: eventRepo.GetOwner().GetLogin(),
|
||||||
Name: eventRepo.GetName(),
|
Name: eventRepo.GetName(),
|
||||||
FullName: eventRepo.GetFullName(),
|
FullName: eventRepo.GetFullName(),
|
||||||
|
|
|
@ -166,7 +166,7 @@ func (c *client) Teams(ctx context.Context, u *model.User) ([]*model.Team, error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo returns the GitHub repository.
|
// 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)
|
client := c.newClientToken(ctx, u.Token)
|
||||||
|
|
||||||
if id.IsValid() {
|
if id.IsValid() {
|
||||||
|
@ -546,7 +546,7 @@ func (c *client) loadChangedFilesFromPullRequest(ctx context.Context, pull *gith
|
||||||
return pipeline, nil
|
return pipeline, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeRemoteID, tmpRepo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,9 +78,9 @@ func Test_github(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("Requesting a repository", func() {
|
g.Describe("Requesting a repository", func() {
|
||||||
g.It("Should return the repository details", 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(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.Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
||||||
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
|
g.Assert(repo.FullName).Equal(fakeRepo.FullName)
|
||||||
|
@ -133,7 +133,7 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeRepo = &model.Repo{
|
fakeRepo = &model.Repo{
|
||||||
ForgeID: "5",
|
ForgeRemoteID: "5",
|
||||||
Owner: "octocat",
|
Owner: "octocat",
|
||||||
Name: "Hello-World",
|
Name: "Hello-World",
|
||||||
FullName: "octocat/Hello-World",
|
FullName: "octocat/Hello-World",
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (g *GitLab) convertGitLabRepo(_repo *gitlab.Project) (*model.Repo, error) {
|
||||||
owner := strings.Join(parts[:len(parts)-1], "/")
|
owner := strings.Join(parts[:len(parts)-1], "/")
|
||||||
name := parts[len(parts)-1]
|
name := parts[len(parts)-1]
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
ForgeID: model.ForgeID(fmt.Sprint(_repo.ID)),
|
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(_repo.ID)),
|
||||||
Owner: owner,
|
Owner: owner,
|
||||||
Name: name,
|
Name: name,
|
||||||
FullName: _repo.PathWithNamespace,
|
FullName: _repo.PathWithNamespace,
|
||||||
|
@ -88,7 +88,7 @@ func convertMergeRequestHook(hook *gitlab.MergeEvent, req *http.Request) (int, *
|
||||||
repo.FullName = fmt.Sprintf("%s/%s", repo.Owner, repo.Name)
|
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
|
repo.Link = target.WebURL
|
||||||
|
|
||||||
if target.GitHTTPURL != "" {
|
if target.GitHTTPURL != "" {
|
||||||
|
@ -142,7 +142,7 @@ func convertPushHook(hook *gitlab.PushEvent) (*model.Repo, *model.Pipeline, erro
|
||||||
return nil, nil, err
|
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.Avatar = hook.Project.AvatarURL
|
||||||
repo.Link = hook.Project.WebURL
|
repo.Link = hook.Project.WebURL
|
||||||
repo.Clone = hook.Project.GitHTTPURL
|
repo.Clone = hook.Project.GitHTTPURL
|
||||||
|
@ -194,7 +194,7 @@ func convertTagHook(hook *gitlab.TagEvent) (*model.Repo, *model.Pipeline, error)
|
||||||
return nil, nil, err
|
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.Avatar = hook.Project.AvatarURL
|
||||||
repo.Link = hook.Project.WebURL
|
repo.Link = hook.Project.WebURL
|
||||||
repo.Clone = hook.Project.GitHTTPURL
|
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.
|
// 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)
|
client, err := newClient(g.URL, user.Token, g.SkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if id.IsValid() {
|
if remoteID.IsValid() {
|
||||||
intID, err := strconv.ParseInt(string(id), 10, 64)
|
intID, err := strconv.ParseInt(string(remoteID), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -682,7 +682,7 @@ func (g *GitLab) loadChangedFilesFromMergeRequest(ctx context.Context, tmpRepo *
|
||||||
return pipeline, nil
|
return pipeline, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeID, tmpRepo.FullName)
|
repo, err := _store.GetRepoNameFallback(tmpRepo.ForgeRemoteID, tmpRepo.FullName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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.
|
// 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)
|
client := c.newClientToken(u.Token)
|
||||||
repo, err := client.GetRepo(owner, name)
|
repo, err := client.GetRepo(owner, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -86,7 +86,7 @@ func Test_gogs(t *testing.T) {
|
||||||
|
|
||||||
g.Describe("Requesting a repository", func() {
|
g.Describe("Requesting a repository", func() {
|
||||||
g.It("Should return the repository details", 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(err).IsNil()
|
||||||
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
g.Assert(repo.Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repo.Name).Equal(fakeRepo.Name)
|
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() {
|
g.It("Should return the repository list", func() {
|
||||||
repos, err := c.Repos(ctx, fakeUser)
|
repos, err := c.Repos(ctx, fakeUser)
|
||||||
g.Assert(err).IsNil()
|
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].Owner).Equal(fakeRepo.Owner)
|
||||||
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
g.Assert(repos[0].Name).Equal(fakeRepo.Name)
|
||||||
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
g.Assert(repos[0].FullName).Equal(fakeRepo.Owner + "/" + fakeRepo.Name)
|
||||||
|
@ -183,7 +183,7 @@ var (
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeRepo = &model.Repo{
|
fakeRepo = &model.Repo{
|
||||||
ForgeID: "5",
|
ForgeRemoteID: "5",
|
||||||
Clone: "http://gogs.com/test_name/repo_name.git",
|
Clone: "http://gogs.com/test_name/repo_name.git",
|
||||||
Owner: "test_name",
|
Owner: "test_name",
|
||||||
Name: "repo_name",
|
Name: "repo_name",
|
||||||
|
|
|
@ -36,7 +36,7 @@ func toRepo(from *gogs.Repository, privateMode bool) *model.Repo {
|
||||||
from.Owner.AvatarUrl,
|
from.Owner.AvatarUrl,
|
||||||
)
|
)
|
||||||
return &model.Repo{
|
return &model.Repo{
|
||||||
ForgeID: model.ForgeID(fmt.Sprint(from.ID)),
|
ForgeRemoteID: model.ForgeRemoteID(fmt.Sprint(from.ID)),
|
||||||
SCMKind: model.RepoGit,
|
SCMKind: model.RepoGit,
|
||||||
Name: name,
|
Name: name,
|
||||||
Owner: from.Owner.UserName,
|
Owner: from.Owner.UserName,
|
||||||
|
|
|
@ -296,13 +296,13 @@ func (_m *Forge) Perm(ctx context.Context, u *model.User, r *model.Repo) (*model
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repo provides a mock function with given fields: 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, id model.ForgeID, owner string, name string) (*model.Repo, error) {
|
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, id, owner, name)
|
ret := _m.Called(ctx, u, remoteID, owner, name)
|
||||||
|
|
||||||
var r0 *model.Repo
|
var r0 *model.Repo
|
||||||
if rf, ok := ret.Get(0).(func(context.Context, *model.User, model.ForgeID, string, string) *model.Repo); ok {
|
if rf, ok := ret.Get(0).(func(context.Context, *model.User, model.ForgeRemoteID, string, string) *model.Repo); ok {
|
||||||
r0 = rf(ctx, u, id, owner, name)
|
r0 = rf(ctx, u, remoteID, owner, name)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(*model.Repo)
|
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
|
var r1 error
|
||||||
if rf, ok := ret.Get(1).(func(context.Context, *model.User, model.ForgeID, string, string) error); ok {
|
if rf, ok := ret.Get(1).(func(context.Context, *model.User, model.ForgeRemoteID, string, string) error); ok {
|
||||||
r1 = rf(ctx, u, id, owner, name)
|
r1 = rf(ctx, u, remoteID, owner, name)
|
||||||
} else {
|
} else {
|
||||||
r1 = ret.Error(1)
|
r1 = ret.Error(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,8 @@ import (
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
ID int64 `json:"id,omitempty" xorm:"pk autoincr 'repo_id'"`
|
ID int64 `json:"id,omitempty" xorm:"pk autoincr 'repo_id'"`
|
||||||
UserID int64 `json:"-" xorm:"repo_user_id"`
|
UserID int64 `json:"-" xorm:"repo_user_id"`
|
||||||
ForgeID ForgeID `json:"-" xorm:"forge_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'"`
|
Owner string `json:"owner" xorm:"UNIQUE(name) 'repo_owner'"`
|
||||||
Name string `json:"name" xorm:"UNIQUE(name) 'repo_name'"`
|
Name string `json:"name" xorm:"UNIQUE(name) 'repo_name'"`
|
||||||
FullName string `json:"full_name" xorm:"UNIQUE 'repo_full_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.
|
// Update updates the repository with values from the given Repo.
|
||||||
func (r *Repo) Update(from *Repo) {
|
func (r *Repo) Update(from *Repo) {
|
||||||
if from.ForgeID.IsValid() {
|
if from.ForgeRemoteID.IsValid() {
|
||||||
r.ForgeID = from.ForgeID
|
r.ForgeRemoteID = from.ForgeRemoteID
|
||||||
}
|
}
|
||||||
r.Owner = from.Owner
|
r.Owner = from.Owner
|
||||||
r.Name = from.Name
|
r.Name = from.Name
|
||||||
|
@ -109,8 +110,8 @@ type RepoPatch struct {
|
||||||
CancelPreviousPipelineEvents *[]WebhookEvent `json:"cancel_previous_pipeline_events"`
|
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"
|
return r != "" && r != "0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ func TestGetPipelineQueue(t *testing.T) {
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,14 +78,14 @@ func TestUserFeed(t *testing.T) {
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test1",
|
Name: "test1",
|
||||||
FullName: "bradrydzewski/test1",
|
FullName: "bradrydzewski/test1",
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
}
|
}
|
||||||
repo2 := &model.Repo{
|
repo2 := &model.Repo{
|
||||||
Owner: "johndoe",
|
Owner: "johndoe",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "johndoe/test2",
|
FullName: "johndoe/test2",
|
||||||
ForgeID: "2",
|
ForgeRemoteID: "2",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,21 +129,21 @@ func TestRepoListLatest(t *testing.T) {
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
}
|
}
|
||||||
repo2 := &model.Repo{
|
repo2 := &model.Repo{
|
||||||
Owner: "test",
|
Owner: "test",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "test/test",
|
FullName: "test/test",
|
||||||
ForgeID: "2",
|
ForgeRemoteID: "2",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
}
|
}
|
||||||
repo3 := &model.Repo{
|
repo3 := &model.Repo{
|
||||||
Owner: "octocat",
|
Owner: "octocat",
|
||||||
Name: "hello-world",
|
Name: "hello-world",
|
||||||
FullName: "octocat/hello-world",
|
FullName: "octocat/hello-world",
|
||||||
ForgeID: "3",
|
ForgeRemoteID: "3",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
}
|
}
|
||||||
assert.NoError(t, store.CreateRepo(repo1))
|
assert.NoError(t, store.CreateRepo(repo1))
|
||||||
|
|
|
@ -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,
|
&renameColumnsBuildsToPipeline,
|
||||||
&renameTableProcsToSteps,
|
&renameTableProcsToSteps,
|
||||||
&renameRemoteToForge,
|
&renameRemoteToForge,
|
||||||
|
&renameForgeIDToForgeRemoteID,
|
||||||
}
|
}
|
||||||
|
|
||||||
var allBeans = []interface{}{
|
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
|
// lookup repo based on name or forge ID if possible
|
||||||
if perm.RepoID == 0 && perm.Repo != nil {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestPermFind(t *testing.T) {
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
}
|
}
|
||||||
assert.NoError(t, store.CreateRepo(repo))
|
assert.NoError(t, store.CreateRepo(repo))
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ func TestPermUpsert(t *testing.T) {
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
}
|
}
|
||||||
assert.NoError(t, store.CreateRepo(repo))
|
assert.NoError(t, store.CreateRepo(repo))
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ func TestPermDelete(t *testing.T) {
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
}
|
}
|
||||||
assert.NoError(t, store.CreateRepo(repo))
|
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))
|
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()
|
sess := s.engine.NewSession()
|
||||||
defer sess.Close()
|
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)
|
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()
|
sess := s.engine.NewSession()
|
||||||
defer sess.Close()
|
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) {
|
func (s storage) getRepoNameFallback(e *xorm.Session, remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error) {
|
||||||
repo, err := s.getRepoForgeID(e, forgeID)
|
repo, err := s.getRepoForgeID(e, remoteID)
|
||||||
if errors.Is(err, types.RecordNotExist) {
|
if errors.Is(err, types.RecordNotExist) {
|
||||||
return s.getRepoName(e, fullName)
|
return s.getRepoName(e, fullName)
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ func (s storage) RepoBatch(repos []*model.Repo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
exist := true
|
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 err != nil {
|
||||||
if errors.Is(err, types.RecordNotExist) {
|
if errors.Is(err, types.RecordNotExist) {
|
||||||
exist = false
|
exist = false
|
||||||
|
@ -186,9 +186,9 @@ func (s storage) RepoBatch(repos []*model.Repo) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if repos[i].ForgeID.IsValid() {
|
if repos[i].ForgeRemoteID.IsValid() {
|
||||||
if _, err := sess.
|
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").
|
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 {
|
Update(repos[i]); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -204,7 +204,7 @@ func (s storage) RepoBatch(repos []*model.Repo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := sess.
|
_, err := sess.
|
||||||
Where("forge_id = ?", repos[i].ForgeID).
|
Where("forge_remote_id = ?", repos[i].ForgeRemoteID).
|
||||||
Get(repos[i])
|
Get(repos[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -139,19 +139,19 @@ func TestRepoList(t *testing.T) {
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
}
|
}
|
||||||
repo2 := &model.Repo{
|
repo2 := &model.Repo{
|
||||||
Owner: "test",
|
Owner: "test",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "test/test",
|
FullName: "test/test",
|
||||||
ForgeID: "2",
|
ForgeRemoteID: "2",
|
||||||
}
|
}
|
||||||
repo3 := &model.Repo{
|
repo3 := &model.Repo{
|
||||||
Owner: "octocat",
|
Owner: "octocat",
|
||||||
Name: "hello-world",
|
Name: "hello-world",
|
||||||
FullName: "octocat/hello-world",
|
FullName: "octocat/hello-world",
|
||||||
ForgeID: "3",
|
ForgeRemoteID: "3",
|
||||||
}
|
}
|
||||||
assert.NoError(t, store.CreateRepo(repo1))
|
assert.NoError(t, store.CreateRepo(repo1))
|
||||||
assert.NoError(t, store.CreateRepo(repo2))
|
assert.NoError(t, store.CreateRepo(repo2))
|
||||||
|
@ -195,25 +195,25 @@ func TestOwnedRepoList(t *testing.T) {
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
}
|
}
|
||||||
repo2 := &model.Repo{
|
repo2 := &model.Repo{
|
||||||
Owner: "test",
|
Owner: "test",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "test/test",
|
FullName: "test/test",
|
||||||
ForgeID: "2",
|
ForgeRemoteID: "2",
|
||||||
}
|
}
|
||||||
repo3 := &model.Repo{
|
repo3 := &model.Repo{
|
||||||
Owner: "octocat",
|
Owner: "octocat",
|
||||||
Name: "hello-world",
|
Name: "hello-world",
|
||||||
FullName: "octocat/hello-world",
|
FullName: "octocat/hello-world",
|
||||||
ForgeID: "3",
|
ForgeRemoteID: "3",
|
||||||
}
|
}
|
||||||
repo4 := &model.Repo{
|
repo4 := &model.Repo{
|
||||||
Owner: "demo",
|
Owner: "demo",
|
||||||
Name: "demo",
|
Name: "demo",
|
||||||
FullName: "demo/demo",
|
FullName: "demo/demo",
|
||||||
ForgeID: "4",
|
ForgeRemoteID: "4",
|
||||||
}
|
}
|
||||||
assert.NoError(t, store.CreateRepo(repo1))
|
assert.NoError(t, store.CreateRepo(repo1))
|
||||||
assert.NoError(t, store.CreateRepo(repo2))
|
assert.NoError(t, store.CreateRepo(repo2))
|
||||||
|
@ -282,7 +282,7 @@ func TestRepoBatch(t *testing.T) {
|
||||||
defer closer()
|
defer closer()
|
||||||
|
|
||||||
if !assert.NoError(t, store.CreateRepo(&model.Repo{
|
if !assert.NoError(t, store.CreateRepo(&model.Repo{
|
||||||
ForgeID: "5",
|
ForgeRemoteID: "5",
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
FullName: "foo/bar",
|
FullName: "foo/bar",
|
||||||
Owner: "foo",
|
Owner: "foo",
|
||||||
|
@ -294,7 +294,7 @@ func TestRepoBatch(t *testing.T) {
|
||||||
|
|
||||||
repos := []*model.Repo{
|
repos := []*model.Repo{
|
||||||
{
|
{
|
||||||
ForgeID: "5",
|
ForgeRemoteID: "5",
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
FullName: "foo/bar",
|
FullName: "foo/bar",
|
||||||
Owner: "foo",
|
Owner: "foo",
|
||||||
|
@ -309,7 +309,7 @@ func TestRepoBatch(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ForgeID: "6",
|
ForgeRemoteID: "6",
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
FullName: "bar/baz",
|
FullName: "bar/baz",
|
||||||
Owner: "bar",
|
Owner: "bar",
|
||||||
|
@ -317,7 +317,7 @@ func TestRepoBatch(t *testing.T) {
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ForgeID: "7",
|
ForgeRemoteID: "7",
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
FullName: "baz/qux",
|
FullName: "baz/qux",
|
||||||
Owner: "baz",
|
Owner: "baz",
|
||||||
|
@ -325,7 +325,7 @@ func TestRepoBatch(t *testing.T) {
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ForgeID: "8",
|
ForgeRemoteID: "8",
|
||||||
UserID: 0, // not activated repos do hot have a user id assigned
|
UserID: 0, // not activated repos do hot have a user id assigned
|
||||||
FullName: "baz/notes",
|
FullName: "baz/notes",
|
||||||
Owner: "baz",
|
Owner: "baz",
|
||||||
|
@ -343,7 +343,7 @@ func TestRepoBatch(t *testing.T) {
|
||||||
assert.True(t, perm.Admin)
|
assert.True(t, perm.Admin)
|
||||||
|
|
||||||
repo := &model.Repo{
|
repo := &model.Repo{
|
||||||
ForgeID: "5",
|
ForgeRemoteID: "5",
|
||||||
FullName: "foo/bar",
|
FullName: "foo/bar",
|
||||||
Owner: "foo",
|
Owner: "foo",
|
||||||
Name: "bar",
|
Name: "bar",
|
||||||
|
@ -444,7 +444,7 @@ func TestRepoRedirection(t *testing.T) {
|
||||||
|
|
||||||
repo := model.Repo{
|
repo := model.Repo{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
|
@ -452,7 +452,7 @@ func TestRepoRedirection(t *testing.T) {
|
||||||
assert.NoError(t, store.CreateRepo(&repo))
|
assert.NoError(t, store.CreateRepo(&repo))
|
||||||
|
|
||||||
repoUpdated := model.Repo{
|
repoUpdated := model.Repo{
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
FullName: "bradrydzewski/test-renamed",
|
FullName: "bradrydzewski/test-renamed",
|
||||||
Owner: "bradrydzewski",
|
Owner: "bradrydzewski",
|
||||||
Name: "test-renamed",
|
Name: "test-renamed",
|
||||||
|
|
|
@ -196,21 +196,21 @@ func TestUsers(t *testing.T) {
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "bradrydzewski/test",
|
FullName: "bradrydzewski/test",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
ForgeID: "1",
|
ForgeRemoteID: "1",
|
||||||
}
|
}
|
||||||
repo2 := &model.Repo{
|
repo2 := &model.Repo{
|
||||||
Owner: "test",
|
Owner: "test",
|
||||||
Name: "test",
|
Name: "test",
|
||||||
FullName: "test/test",
|
FullName: "test/test",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
ForgeID: "2",
|
ForgeRemoteID: "2",
|
||||||
}
|
}
|
||||||
repo3 := &model.Repo{
|
repo3 := &model.Repo{
|
||||||
Owner: "octocat",
|
Owner: "octocat",
|
||||||
Name: "hello-world",
|
Name: "hello-world",
|
||||||
FullName: "octocat/hello-world",
|
FullName: "octocat/hello-world",
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
ForgeID: "3",
|
ForgeRemoteID: "3",
|
||||||
}
|
}
|
||||||
g.Assert(store.CreateRepo(repo1)).IsNil()
|
g.Assert(store.CreateRepo(repo1)).IsNil()
|
||||||
g.Assert(store.CreateRepo(repo2)).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
|
// 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)
|
ret := _m.Called(_a0)
|
||||||
|
|
||||||
var r0 *model.Repo
|
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)
|
r0 = rf(_a0)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
|
@ -724,7 +724,7 @@ func (_m *Store) GetRepoForgeID(_a0 model.ForgeID) (*model.Repo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 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)
|
r1 = rf(_a0)
|
||||||
} else {
|
} else {
|
||||||
r1 = ret.Error(1)
|
r1 = ret.Error(1)
|
||||||
|
@ -756,13 +756,13 @@ func (_m *Store) GetRepoName(_a0 string) (*model.Repo, error) {
|
||||||
return r0, r1
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRepoNameFallback provides a mock function with given fields: forgeID, fullName
|
// GetRepoNameFallback provides a mock function with given fields: remoteID, fullName
|
||||||
func (_m *Store) GetRepoNameFallback(forgeID model.ForgeID, fullName string) (*model.Repo, error) {
|
func (_m *Store) GetRepoNameFallback(remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error) {
|
||||||
ret := _m.Called(forgeID, fullName)
|
ret := _m.Called(remoteID, fullName)
|
||||||
|
|
||||||
var r0 *model.Repo
|
var r0 *model.Repo
|
||||||
if rf, ok := ret.Get(0).(func(model.ForgeID, string) *model.Repo); ok {
|
if rf, ok := ret.Get(0).(func(model.ForgeRemoteID, string) *model.Repo); ok {
|
||||||
r0 = rf(forgeID, fullName)
|
r0 = rf(remoteID, fullName)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
if ret.Get(0) != nil {
|
||||||
r0 = ret.Get(0).(*model.Repo)
|
r0 = ret.Get(0).(*model.Repo)
|
||||||
|
@ -770,8 +770,8 @@ func (_m *Store) GetRepoNameFallback(forgeID model.ForgeID, fullName string) (*m
|
||||||
}
|
}
|
||||||
|
|
||||||
var r1 error
|
var r1 error
|
||||||
if rf, ok := ret.Get(1).(func(model.ForgeID, string) error); ok {
|
if rf, ok := ret.Get(1).(func(model.ForgeRemoteID, string) error); ok {
|
||||||
r1 = rf(forgeID, fullName)
|
r1 = rf(remoteID, fullName)
|
||||||
} else {
|
} else {
|
||||||
r1 = ret.Error(1)
|
r1 = ret.Error(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,9 @@ type Store interface {
|
||||||
// GetRepo gets a repo by unique ID.
|
// GetRepo gets a repo by unique ID.
|
||||||
GetRepo(int64) (*model.Repo, error)
|
GetRepo(int64) (*model.Repo, error)
|
||||||
// GetRepoForgeID gets a repo by its forge ID.
|
// 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 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 gets a repo by its full name.
|
||||||
GetRepoName(string) (*model.Repo, error)
|
GetRepoName(string) (*model.Repo, error)
|
||||||
// GetRepoCount gets a count of all repositories in the system.
|
// GetRepoCount gets a count of all repositories in the system.
|
||||||
|
|
Loading…
Reference in a new issue