Skip to content

Commit 17eec88

Browse files
committed
feat: add Codeberg as a supported git hosting service
Codeberg is a Gitea-based git hosting service that uses the same URL patterns for pull requests and commits. This adds native support so users don't need to manually configure it.
1 parent 3201695 commit 17eec88

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

docs-master/Config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ services:
10781078
Where:
10791079

10801080
- `gitDomain` stands for the domain used by git itself (i.e. the one present on clone URLs), e.g. `git.work.com`
1081-
- `provider` is one of `github`, `bitbucket`, `bitbucketServer`, `azuredevops`, `gitlab` or `gitea`
1081+
- `provider` is one of `github`, `bitbucket`, `bitbucketServer`, `azuredevops`, `gitlab`, `gitea` or `codeberg`
10821082
- `webDomain` is the URL where your git service exposes a web interface and APIs, e.g. `gitservice.work.com`
10831083

10841084
## Predefined commit message prefix

docs/Config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ services:
10781078
Where:
10791079

10801080
- `gitDomain` stands for the domain used by git itself (i.e. the one present on clone URLs), e.g. `git.work.com`
1081-
- `provider` is one of `github`, `bitbucket`, `bitbucketServer`, `azuredevops`, `gitlab` or `gitea`
1081+
- `provider` is one of `github`, `bitbucket`, `bitbucketServer`, `azuredevops`, `gitlab`, `gitea` or `codeberg`
10821082
- `webDomain` is the URL where your git service exposes a web interface and APIs, e.g. `gitservice.work.com`
10831083

10841084
## Predefined commit message prefix

pkg/commands/hosting_service/definitions.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,23 @@ var giteaServiceDef = ServiceDefinition{
7575
repoURLTemplate: defaultRepoURLTemplate,
7676
}
7777

78+
var codebergServiceDef = ServiceDefinition{
79+
provider: "codeberg",
80+
pullRequestURLIntoDefaultBranch: "/compare/{{.From}}",
81+
pullRequestURLIntoTargetBranch: "/compare/{{.To}}...{{.From}}",
82+
commitURL: "/commit/{{.CommitHash}}",
83+
regexStrings: defaultUrlRegexStrings,
84+
repoURLTemplate: defaultRepoURLTemplate,
85+
}
86+
7887
var serviceDefinitions = []ServiceDefinition{
7988
githubServiceDef,
8089
bitbucketServiceDef,
8190
gitLabServiceDef,
8291
azdoServiceDef,
8392
bitbucketServerServiceDef,
8493
giteaServiceDef,
94+
codebergServiceDef,
8595
}
8696

8797
var defaultServiceDomains = []ServiceDomain{
@@ -110,4 +120,9 @@ var defaultServiceDomains = []ServiceDomain{
110120
gitDomain: "try.gitea.io",
111121
webDomain: "try.gitea.io",
112122
},
123+
{
124+
serviceDefinition: codebergServiceDef,
125+
gitDomain: "codeberg.org",
126+
webDomain: "codeberg.org",
127+
},
113128
}

pkg/commands/hosting_service/hosting_service_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,44 @@ func TestGetPullRequestURL(t *testing.T) {
421421
assert.Equal(t, "https://mycompany.gitea.io/myproject/myrepo/compare/dev...feature%2Fnew", url)
422422
},
423423
},
424+
{
425+
testName: "Opens a link to new pull request on Codeberg (SSH)",
426+
from: "feature/new",
427+
remoteUrl: "[email protected]:johndoe/myrepo.git",
428+
test: func(url string, err error) {
429+
assert.NoError(t, err)
430+
assert.Equal(t, "https://codeberg.org/johndoe/myrepo/compare/feature%2Fnew", url)
431+
},
432+
},
433+
{
434+
testName: "Opens a link to new pull request on Codeberg (SSH) with specific target",
435+
from: "feature/new",
436+
to: "dev",
437+
remoteUrl: "[email protected]:johndoe/myrepo.git",
438+
test: func(url string, err error) {
439+
assert.NoError(t, err)
440+
assert.Equal(t, "https://codeberg.org/johndoe/myrepo/compare/dev...feature%2Fnew", url)
441+
},
442+
},
443+
{
444+
testName: "Opens a link to new pull request on Codeberg (HTTP)",
445+
from: "feature/new",
446+
remoteUrl: "https://codeberg.org/johndoe/myrepo.git",
447+
test: func(url string, err error) {
448+
assert.NoError(t, err)
449+
assert.Equal(t, "https://codeberg.org/johndoe/myrepo/compare/feature%2Fnew", url)
450+
},
451+
},
452+
{
453+
testName: "Opens a link to new pull request on Codeberg (HTTP) with specific target",
454+
from: "feature/new",
455+
to: "dev",
456+
remoteUrl: "https://codeberg.org/johndoe/myrepo.git",
457+
test: func(url string, err error) {
458+
assert.NoError(t, err)
459+
assert.Equal(t, "https://codeberg.org/johndoe/myrepo/compare/dev...feature%2Fnew", url)
460+
},
461+
},
424462
{
425463
testName: "Throws an error if git service is unsupported",
426464
from: "feature/divide-operation",
@@ -505,7 +543,7 @@ func TestGetPullRequestURL(t *testing.T) {
505543
assert.NoError(t, err)
506544
assert.Equal(t, "https://bitbucket.org/johndoe/social_network/pull-requests/new?source=feature%2Fprofile-page&t=1", url)
507545
},
508-
expectedLoggedErrors: []string{"Unknown git service type: 'noservice'. Expected one of github, bitbucket, gitlab, azuredevops, bitbucketServer, gitea"},
546+
expectedLoggedErrors: []string{"Unknown git service type: 'noservice'. Expected one of github, bitbucket, gitlab, azuredevops, bitbucketServer, gitea, codeberg"},
509547
},
510548
{
511549
testName: "Escapes reserved URL characters in from branch name",

0 commit comments

Comments
 (0)