Skip to content

Commit def1c96

Browse files
authored
Support migration from AWS CodeCommit (go-gitea#31981)
This PR adds support for migrating repos from [AWS CodeCommit](https://docs.aws.amazon.com/codecommit/latest/userguide/welcome.html). The access key ID and secret access key are required to get repository information and pull requests. And [HTTPS Git credentials](https://docs.aws.amazon.com/codecommit/latest/userguide/setting-up-gc.html) are required to clone the repository. <img src="https://github.com/user-attachments/assets/82ecb2d0-8d43-42b0-b5af-f5347a13b9d0" width="680" /> The AWS CodeCommit icon is from [AWS Architecture Icons](https://aws.amazon.com/architecture/icons/). <img src="https://github.com/user-attachments/assets/3c44d21f-d753-40f5-9eae-5d3589e0d50d" width="320" />
1 parent d9a7748 commit def1c96

File tree

15 files changed

+513
-9
lines changed

15 files changed

+513
-9
lines changed

assets/go-licenses.json

+50
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ require (
2323
github.com/PuerkitoBio/goquery v1.9.2
2424
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.2
2525
github.com/alecthomas/chroma/v2 v2.14.0
26+
github.com/aws/aws-sdk-go v1.43.21
27+
github.com/aws/aws-sdk-go-v2/credentials v1.17.30
28+
github.com/aws/aws-sdk-go-v2/service/codecommit v1.25.1
2629
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb
2730
github.com/blevesearch/bleve/v2 v2.4.2
2831
github.com/buildkite/terminal-to-html/v3 v3.12.1
@@ -146,6 +149,10 @@ require (
146149
github.com/andybalholm/cascadia v1.3.2 // indirect
147150
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
148151
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
152+
github.com/aws/aws-sdk-go-v2 v1.30.4 // indirect
153+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 // indirect
154+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 // indirect
155+
github.com/aws/smithy-go v1.20.4 // indirect
149156
github.com/aymerick/douceur v0.2.0 // indirect
150157
github.com/beorn7/perks v1.0.1 // indirect
151158
github.com/bits-and-blooms/bitset v1.13.0 // indirect

go.sum

+18
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPd
109109
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
110110
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
111111
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
112+
github.com/aws/aws-sdk-go v1.43.21 h1:E4S2eX3d2gKJyI/ISrcIrSwXwqjIvCK85gtBMt4sAPE=
113+
github.com/aws/aws-sdk-go v1.43.21/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
114+
github.com/aws/aws-sdk-go-v2 v1.30.4 h1:frhcagrVNrzmT95RJImMHgabt99vkXGslubDaDagTk8=
115+
github.com/aws/aws-sdk-go-v2 v1.30.4/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0=
116+
github.com/aws/aws-sdk-go-v2/credentials v1.17.30 h1:aau/oYFtibVovr2rDt8FHlU17BTicFEMAi29V1U+L5Q=
117+
github.com/aws/aws-sdk-go-v2/credentials v1.17.30/go.mod h1:BPJ/yXV92ZVq6G8uYvbU0gSl8q94UB63nMT5ctNO38g=
118+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16 h1:TNyt/+X43KJ9IJJMjKfa3bNTiZbUP7DeCxfbTROESwY=
119+
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.16/go.mod h1:2DwJF39FlNAUiX5pAc0UNeiz16lK2t7IaFcm0LFHEgc=
120+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16 h1:jYfy8UPmd+6kJW5YhY0L1/KftReOGxI/4NtVSTh9O/I=
121+
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.16/go.mod h1:7ZfEPZxkW42Afq4uQB8H2E2e6ebh6mXTueEpYzjCzcs=
122+
github.com/aws/aws-sdk-go-v2/service/codecommit v1.25.1 h1:mOOALIM4JzhYkq3voCBbmZqmyEVEhHsfasMTbVxLkNs=
123+
github.com/aws/aws-sdk-go-v2/service/codecommit v1.25.1/go.mod h1:6zf5j3mIUXKM0s2iz5ttR2Qwq+o47D0jotpAyaKgZRA=
124+
github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4=
125+
github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
112126
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
113127
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
114128
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -504,6 +518,9 @@ github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LF
504518
github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
505519
github.com/jhillyerd/enmime v1.2.0 h1:dIu1IPEymQgoT2dzuB//ttA/xcV40NMPpQtmd4wslHk=
506520
github.com/jhillyerd/enmime v1.2.0/go.mod h1:FRFuUPCLh8PByQv+8xRcLO9QHqaqTqreYhopv5eyk4I=
521+
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
522+
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
523+
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
507524
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
508525
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
509526
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -894,6 +911,7 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
894911
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
895912
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
896913
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
914+
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
897915
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
898916
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
899917
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=

modules/migration/options.go

+3
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ type MigrateOptions struct {
3838
ReleaseAssets bool
3939
MigrateToRepoID int64
4040
MirrorInterval string `json:"mirror_interval"`
41+
42+
AWSAccessKeyID string
43+
AWSSecretAccessKey string
4144
}

modules/structs/repo.go

+16-9
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,16 @@ type GitServiceType int
291291

292292
// enumerate all GitServiceType
293293
const (
294-
NotMigrated GitServiceType = iota // 0 not migrated from external sites
295-
PlainGitService // 1 plain git service
296-
GithubService // 2 github.com
297-
GiteaService // 3 gitea service
298-
GitlabService // 4 gitlab service
299-
GogsService // 5 gogs service
300-
OneDevService // 6 onedev service
301-
GitBucketService // 7 gitbucket service
302-
CodebaseService // 8 codebase service
294+
NotMigrated GitServiceType = iota // 0 not migrated from external sites
295+
PlainGitService // 1 plain git service
296+
GithubService // 2 github.com
297+
GiteaService // 3 gitea service
298+
GitlabService // 4 gitlab service
299+
GogsService // 5 gogs service
300+
OneDevService // 6 onedev service
301+
GitBucketService // 7 gitbucket service
302+
CodebaseService // 8 codebase service
303+
CodeCommitService // 9 codecommit service
303304
)
304305

305306
// Name represents the service type's name
@@ -325,6 +326,8 @@ func (gt GitServiceType) Title() string {
325326
return "GitBucket"
326327
case CodebaseService:
327328
return "Codebase"
329+
case CodeCommitService:
330+
return "CodeCommit"
328331
case PlainGitService:
329332
return "Git"
330333
}
@@ -361,6 +364,9 @@ type MigrateRepoOptions struct {
361364
PullRequests bool `json:"pull_requests"`
362365
Releases bool `json:"releases"`
363366
MirrorInterval string `json:"mirror_interval"`
367+
368+
AWSAccessKeyID string `json:"aws_access_key_id"`
369+
AWSSecretAccessKey string `json:"aws_secret_access_key"`
364370
}
365371

366372
// TokenAuth represents whether a service type supports token-based auth
@@ -382,6 +388,7 @@ var SupportedFullGitService = []GitServiceType{
382388
OneDevService,
383389
GitBucketService,
384390
CodebaseService,
391+
CodeCommitService,
385392
}
386393

387394
// RepoTransfer represents a pending repo transfer

options/locale/locale_en-US.ini

+5
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,11 @@ migrate.gogs.description = Migrate data from notabug.org or other Gogs instances
11761176
migrate.onedev.description = Migrate data from code.onedev.io or other OneDev instances.
11771177
migrate.codebase.description = Migrate data from codebasehq.com.
11781178
migrate.gitbucket.description = Migrate data from GitBucket instances.
1179+
migrate.codecommit.description = Migrate data from AWS CodeCommit.
1180+
migrate.codecommit.aws_access_key_id = AWS Access Key ID
1181+
migrate.codecommit.aws_secret_access_key = AWS Secret Access Key
1182+
migrate.codecommit.https_git_credentials_username = HTTPS Git Credentials Username
1183+
migrate.codecommit.https_git_credentials_password = HTTPS Git Credentials Password
11791184
migrate.migrating_git = Migrating Git Data
11801185
migrate.migrating_topics = Migrating Topics
11811186
migrate.migrating_milestones = Migrating Milestones

public/assets/img/svg/gitea-codecommit.svg

+1
Loading

routers/api/v1/repo/migrate.go

+4
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ func Migrate(ctx *context.APIContext) {
169169
opts.PullRequests = false
170170
opts.Releases = false
171171
}
172+
if gitServiceType == api.CodeCommitService {
173+
opts.AWSAccessKeyID = form.AWSAccessKeyID
174+
opts.AWSSecretAccessKey = form.AWSSecretAccessKey
175+
}
172176

173177
repo, err := repo_service.CreateRepositoryDirectly(ctx, ctx.Doer, repoOwner, repo_service.CreateRepoOptions{
174178
Name: opts.RepoName,

routers/web/repo/migrate.go

+4
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ func MigratePost(ctx *context.Context) {
231231
opts.PullRequests = false
232232
opts.Releases = false
233233
}
234+
if form.Service == structs.CodeCommitService {
235+
opts.AWSAccessKeyID = form.AWSAccessKeyID
236+
opts.AWSSecretAccessKey = form.AWSSecretAccessKey
237+
}
234238

235239
err = repo_model.CheckCreateRepository(ctx, ctx.Doer, ctxUser, opts.RepoName, false)
236240
if err != nil {

services/convert/utils.go

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func ToGitServiceType(value string) structs.GitServiceType {
3636
return structs.OneDevService
3737
case "gitbucket":
3838
return structs.GitBucketService
39+
case "codecommit":
40+
return structs.CodeCommitService
3941
default:
4042
return structs.PlainGitService
4143
}

services/forms/repo_form.go

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type MigrateRepoForm struct {
7979
PullRequests bool `json:"pull_requests"`
8080
Releases bool `json:"releases"`
8181
MirrorInterval string `json:"mirror_interval"`
82+
83+
AWSAccessKeyID string `json:"aws_access_key_id"`
84+
AWSSecretAccessKey string `json:"aws_secret_access_key"`
8285
}
8386

8487
// Validate validates the fields

0 commit comments

Comments
 (0)