Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 400b083

Browse files
authored
Merge pull request #888 from jeromedoucet/tech/add_gog_repository_not_found
plumbing/transport/internal: common, support Gogs for ErrRepositoryNotFound
2 parents 3bd5e82 + 54d8c38 commit 400b083

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

plumbing/transport/internal/common/common.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ var (
382382
gitProtocolNotFoundErr = "ERR \n Repository not found."
383383
gitProtocolNoSuchErr = "ERR no such repository"
384384
gitProtocolAccessDeniedErr = "ERR access denied"
385+
gogsAccessDeniedErr = "Gogs: Repository does not exist or you do not have access"
385386
)
386387

387388
func isRepoNotFoundError(s string) bool {
@@ -409,6 +410,10 @@ func isRepoNotFoundError(s string) bool {
409410
return true
410411
}
411412

413+
if strings.HasPrefix(s, gogsAccessDeniedErr) {
414+
return true
415+
}
416+
412417
return false
413418
}
414419

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package common
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
. "gopkg.in/check.v1"
8+
)
9+
10+
func Test(t *testing.T) { TestingT(t) }
11+
12+
type CommonSuite struct{}
13+
14+
var _ = Suite(&CommonSuite{})
15+
16+
func (s *CommonSuite) TestIsRepoNotFoundErrorForUnknowSource(c *C) {
17+
msg := "unknown system is complaining of something very sad :("
18+
19+
isRepoNotFound := isRepoNotFoundError(msg)
20+
21+
c.Assert(isRepoNotFound, Equals, false)
22+
}
23+
24+
func (s *CommonSuite) TestIsRepoNotFoundErrorForGithub(c *C) {
25+
msg := fmt.Sprintf("%s : some error stuf", githubRepoNotFoundErr)
26+
27+
isRepoNotFound := isRepoNotFoundError(msg)
28+
29+
c.Assert(isRepoNotFound, Equals, true)
30+
}
31+
32+
func (s *CommonSuite) TestIsRepoNotFoundErrorForBitBucket(c *C) {
33+
msg := fmt.Sprintf("%s : some error stuf", bitbucketRepoNotFoundErr)
34+
35+
isRepoNotFound := isRepoNotFoundError(msg)
36+
37+
c.Assert(isRepoNotFound, Equals, true)
38+
}
39+
40+
func (s *CommonSuite) TestIsRepoNotFoundErrorForLocal(c *C) {
41+
msg := fmt.Sprintf("some error stuf : %s", localRepoNotFoundErr)
42+
43+
isRepoNotFound := isRepoNotFoundError(msg)
44+
45+
c.Assert(isRepoNotFound, Equals, true)
46+
}
47+
48+
func (s *CommonSuite) TestIsRepoNotFoundErrorForGitProtocolNotFound(c *C) {
49+
msg := fmt.Sprintf("%s : some error stuf", gitProtocolNotFoundErr)
50+
51+
isRepoNotFound := isRepoNotFoundError(msg)
52+
53+
c.Assert(isRepoNotFound, Equals, true)
54+
}
55+
56+
func (s *CommonSuite) TestIsRepoNotFoundErrorForGitProtocolNoSuch(c *C) {
57+
msg := fmt.Sprintf("%s : some error stuf", gitProtocolNoSuchErr)
58+
59+
isRepoNotFound := isRepoNotFoundError(msg)
60+
61+
c.Assert(isRepoNotFound, Equals, true)
62+
}
63+
64+
func (s *CommonSuite) TestIsRepoNotFoundErrorForGitProtocolAccessDenied(c *C) {
65+
msg := fmt.Sprintf("%s : some error stuf", gitProtocolAccessDeniedErr)
66+
67+
isRepoNotFound := isRepoNotFoundError(msg)
68+
69+
c.Assert(isRepoNotFound, Equals, true)
70+
}
71+
72+
func (s *CommonSuite) TestIsRepoNotFoundErrorForGogsAccessDenied(c *C) {
73+
msg := fmt.Sprintf("%s : some error stuf", gogsAccessDeniedErr)
74+
75+
isRepoNotFound := isRepoNotFoundError(msg)
76+
77+
c.Assert(isRepoNotFound, Equals, true)
78+
}

0 commit comments

Comments
 (0)