Skip to content

Commit 517c511

Browse files
committed
Add github projects migrations support
1 parent bc05ddc commit 517c511

File tree

6 files changed

+99
-0
lines changed

6 files changed

+99
-0
lines changed

modules/migrations/base/downloader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Downloader interface {
2424
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
2525
GetReviews(pullRequestNumber int64) ([]*Review, error)
2626
FormatCloneURL(opts MigrateOptions, remoteAddr string) (string, error)
27+
GetProjects() ([]*Project, error)
2728
}
2829

2930
// DownloaderFactory defines an interface to match a downloader implementation and create a downloader

modules/migrations/base/project.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package base
6+
7+
import "time"
8+
9+
// Project is a standard project information
10+
type Project struct {
11+
Number int
12+
Name string
13+
Description string `xorm:"TEXT"`
14+
State string
15+
CreatedAt time.Time
16+
UpdatedAt time.Time
17+
Columns []*ProjectColumn
18+
}
19+
20+
type ProjectColumn struct {
21+
Cards []*ProjectCard
22+
}
23+
24+
type ProjectCard struct {
25+
}

modules/migrations/base/uploader.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Uploader interface {
1818
CreateComments(comments ...*Comment) error
1919
CreatePullRequests(prs ...*PullRequest) error
2020
CreateReviews(reviews ...*Review) error
21+
CreateProjects(projects ...*Project) error
2122
Rollback() error
2223
Finish() error
2324
Close()

modules/migrations/github.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,3 +740,43 @@ func (g *GithubDownloaderV3) GetReviews(pullRequestNumber int64) ([]*base.Review
740740
}
741741
return allReviews, nil
742742
}
743+
744+
func convertGithubProject(gp *github.Project) *base.Project {
745+
var desc string
746+
if gp.Body != nil {
747+
desc = *gp.Body
748+
}
749+
return &base.Project{
750+
Name: *gp.Name,
751+
Number: *gp.Number,
752+
Description: desc,
753+
State: *gp.State,
754+
CreatedAt: gp.GetCreatedAt().Time,
755+
UpdatedAt: gp.GetUpdatedAt().Time,
756+
}
757+
}
758+
759+
func (g *GithubDownloaderV3) GetProjects() ([]*base.Project, error) {
760+
var projects = make([]*base.Project, 0, 100)
761+
opt := github.ListOptions{
762+
PerPage: 100,
763+
}
764+
for {
765+
g.sleep()
766+
gprojects, resp, err := g.client.Repositories.ListProjects(g.ctx, g.repoOwner, g.repoName, &github.ProjectListOptions{
767+
ListOptions: opt,
768+
})
769+
if err != nil {
770+
return nil, fmt.Errorf("error while listing projects: %v", err)
771+
}
772+
g.rate = &resp.Rate
773+
for _, p := range gprojects {
774+
projects = append(projects, convertGithubProject(p))
775+
}
776+
if resp.NextPage == 0 {
777+
break
778+
}
779+
opt.Page = resp.NextPage
780+
}
781+
return projects, nil
782+
}

modules/migrations/gitlab.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,3 +647,8 @@ func (g *GitlabDownloader) awardToReaction(award *gitlab.AwardEmoji) *base.React
647647
Content: award.Name,
648648
}
649649
}
650+
651+
// GetProjects returns projects for the repository
652+
func (g *GitlabDownloader) GetProjects() ([]*base.Project, error) {
653+
return nil, ErrNotSupported
654+
}

modules/structs/repo.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,30 @@ var (
283283
GogsService,
284284
}
285285
)
286+
287+
// MigrateRepoOption options for migrating a repository from an external service
288+
type MigrateRepoOption struct {
289+
// required: true
290+
CloneAddr string `json:"clone_addr" binding:"Required"`
291+
AuthUsername string `json:"auth_username"`
292+
AuthPassword string `json:"auth_password"`
293+
AuthToken string `json:"auth_token"`
294+
// required: true
295+
UID int `json:"uid" binding:"Required"`
296+
// required: true
297+
RepoName string `json:"repo_name" binding:"Required"`
298+
Mirror bool `json:"mirror"`
299+
Private bool `json:"private"`
300+
Description string `json:"description"`
301+
OriginalURL string
302+
GitServiceType GitServiceType
303+
Wiki bool
304+
Issues bool
305+
Milestones bool
306+
Labels bool
307+
Releases bool
308+
Comments bool
309+
PullRequests bool
310+
Projects bool
311+
MigrateToRepoID int64
312+
}

0 commit comments

Comments
 (0)