Skip to content

WIP: Add github projects migrations support #12819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/migrations/base/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Downloader interface {
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
GetReviews(pullRequestNumber int64) ([]*Review, error)
FormatCloneURL(opts MigrateOptions, remoteAddr string) (string, error)
GetProjects() ([]*Project, error)
}

// DownloaderFactory defines an interface to match a downloader implementation and create a downloader
Expand Down
25 changes: 25 additions & 0 deletions modules/migrations/base/project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package base

import "time"

// Project is a standard project information
type Project struct {
Number int
Name string
Description string `xorm:"TEXT"`
State string
CreatedAt time.Time
UpdatedAt time.Time
Columns []*ProjectColumn
}

type ProjectColumn struct {
Cards []*ProjectCard
}

type ProjectCard struct {
}
1 change: 1 addition & 0 deletions modules/migrations/base/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Uploader interface {
CreateComments(comments ...*Comment) error
CreatePullRequests(prs ...*PullRequest) error
CreateReviews(reviews ...*Review) error
CreateProjects(projects ...*Project) error
Rollback() error
Finish() error
Close()
Expand Down
40 changes: 40 additions & 0 deletions modules/migrations/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,43 @@ func (g *GithubDownloaderV3) GetReviews(pullRequestNumber int64) ([]*base.Review
}
return allReviews, nil
}

func convertGithubProject(gp *github.Project) *base.Project {
var desc string
if gp.Body != nil {
desc = *gp.Body
}
return &base.Project{
Name: *gp.Name,
Number: *gp.Number,
Description: desc,
State: *gp.State,
CreatedAt: gp.GetCreatedAt().Time,
UpdatedAt: gp.GetUpdatedAt().Time,
}
}

func (g *GithubDownloaderV3) GetProjects() ([]*base.Project, error) {
var projects = make([]*base.Project, 0, 100)
opt := github.ListOptions{
PerPage: 100,
}
for {
g.sleep()
gprojects, resp, err := g.client.Repositories.ListProjects(g.ctx, g.repoOwner, g.repoName, &github.ProjectListOptions{
ListOptions: opt,
})
if err != nil {
return nil, fmt.Errorf("error while listing projects: %v", err)
}
g.rate = &resp.Rate
for _, p := range gprojects {
projects = append(projects, convertGithubProject(p))
}
if resp.NextPage == 0 {
break
}
opt.Page = resp.NextPage
}
return projects, nil
}
5 changes: 5 additions & 0 deletions modules/migrations/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,8 @@ func (g *GitlabDownloader) awardToReaction(award *gitlab.AwardEmoji) *base.React
Content: award.Name,
}
}

// GetProjects returns projects for the repository
func (g *GitlabDownloader) GetProjects() ([]*base.Project, error) {
return nil, ErrNotSupported
}
27 changes: 27 additions & 0 deletions modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,30 @@ var (
GogsService,
}
)

// MigrateRepoOption options for migrating a repository from an external service
type MigrateRepoOption struct {
// required: true
CloneAddr string `json:"clone_addr" binding:"Required"`
AuthUsername string `json:"auth_username"`
AuthPassword string `json:"auth_password"`
AuthToken string `json:"auth_token"`
// required: true
UID int `json:"uid" binding:"Required"`
// required: true
RepoName string `json:"repo_name" binding:"Required"`
Mirror bool `json:"mirror"`
Private bool `json:"private"`
Description string `json:"description"`
OriginalURL string
GitServiceType GitServiceType
Wiki bool
Issues bool
Milestones bool
Labels bool
Releases bool
Comments bool
PullRequests bool
Projects bool
MigrateToRepoID int64
}