Skip to content

Commit 7583b55

Browse files
author
Chun-Hung Hsiao
authored
Merge branch 'master' into pr-create
2 parents 4ebe558 + 5d633c6 commit 7583b55

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+641
-112
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Fixed
1313
- Fix issue with GitHub enterprise deep link including API prefix, from [@bradrydzewski](https://github.com/bradrydzewski).
14+
- Fix issue with GitHub deploy hooks for commits having an invalid reference, from [@bradrydzewski](https://github.com/bradrydzewski).
1415

1516
## [1.6.0]
1617
### Added

scm/content.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ type (
1616
// ContentParams provide parameters for creating and
1717
// updating repository content.
1818
ContentParams struct {
19-
Ref string
20-
Branch string
21-
Message string
22-
Data []byte
19+
Ref string
20+
Branch string
21+
Message string
22+
Data []byte
23+
Sha string
24+
Signature Signature
2325
}
2426

2527
// ContentInfo stores the kind of any content in a repository.

scm/driver/bitbucket/repo.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ import (
1313
"github.com/drone/go-scm/scm"
1414
)
1515

16+
type cloneLink struct {
17+
link
18+
Name string `json:"name"`
19+
}
20+
1621
type repository struct {
1722
UUID string `json:"uuid"`
1823
SCM string `json:"scm"`
@@ -24,6 +29,10 @@ type repository struct {
2429
Type string `json:"type"`
2530
Name string `json:"name"`
2631
} `json:"mainbranch"`
32+
Links struct {
33+
HTML link `json:"html"`
34+
Clone []cloneLink `json:"clone"`
35+
} `json:"links"`
2736
}
2837

2938
type perms struct {
@@ -176,16 +185,36 @@ func convertRepository(from *repository) *scm.Repository {
176185
ID: from.UUID,
177186
Name: name,
178187
Namespace: namespace,
179-
Link: fmt.Sprintf("https://bitbucket.org/%s", from.FullName),
188+
Link: from.Links.HTML.Href,
180189
Branch: from.Mainbranch.Name,
181190
Private: from.IsPrivate,
182-
Clone: fmt.Sprintf("https://bitbucket.org/%s.git", from.FullName),
183-
CloneSSH: fmt.Sprintf("[email protected]:%s.git", from.FullName),
191+
CloneSSH: extractCloneLink(from.Links.Clone, "ssh"),
192+
Clone: anonymizeLink(extractCloneLink(from.Links.Clone, "https", "http")),
184193
Created: from.CreatedOn,
185194
Updated: from.UpdatedOn,
186195
}
187196
}
188197

198+
func extractCloneLink(links []cloneLink, names ...string) (href string) {
199+
for _, name := range names {
200+
for _, link := range links {
201+
if link.Name == name && link.Href != "" {
202+
return link.Href
203+
}
204+
}
205+
}
206+
return
207+
}
208+
209+
func anonymizeLink(link string) (href string) {
210+
parsed, err := url.Parse(link)
211+
if err != nil {
212+
return link
213+
}
214+
parsed.User = nil
215+
return parsed.String()
216+
}
217+
189218
func convertPerms(from *perms) *scm.Perm {
190219
to := new(scm.Perm)
191220
if len(from.Values) != 1 {

scm/driver/gitea/repo.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func convertRepository(src *repository) *scm.Repository {
189189
Private: src.Private,
190190
Clone: src.CloneURL,
191191
CloneSSH: src.SSHURL,
192+
Link: src.HTMLURL,
192193
}
193194
}
194195

scm/driver/gitea/testdata/repo.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"Private": true,
1212
"Clone": "https://try.gitea.io/go-gitea/gitea.git",
1313
"CloneSSH": "[email protected]:go-gitea/gitea.git",
14-
"Link": "",
14+
"Link": "https://try.gitea.io/go-gitea/gitea",
1515
"Created": "0001-01-01T00:00:00Z",
1616
"Updated": "0001-01-01T00:00:00Z"
1717
}

scm/driver/gitea/testdata/repos.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"Private": true,
1313
"Clone": "https://try.gitea.io/go-gitea/gitea.git",
1414
"CloneSSH": "[email protected]:go-gitea/gitea.git",
15-
"Link": "",
15+
"Link": "https://try.gitea.io/go-gitea/gitea",
1616
"Created": "0001-01-01T00:00:00Z",
1717
"Updated": "0001-01-01T00:00:00Z"
1818
}

scm/driver/gitea/testdata/webhooks/branch_create.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"Private": true,
1313
"Clone": "http://try.gitea.io/gogits/hello-world.git",
1414
"CloneSSH": "git@localhost:gogits/hello-world.git",
15-
"Link": "",
15+
"Link": "http://try.gitea.io/gogits/hello-world",
1616
"Created": "0001-01-01T00:00:00Z",
1717
"Updated": "0001-01-01T00:00:00Z"
1818
},

scm/driver/gitea/testdata/webhooks/branch_delete.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"Private": true,
1313
"Clone": "http://try.gitea.io/gogits/hello-world.git",
1414
"CloneSSH": "git@localhost:gogits/hello-world.git",
15-
"Link": "",
15+
"Link": "http://try.gitea.io/gogits/hello-world",
1616
"Created": "0001-01-01T00:00:00Z",
1717
"Updated": "0001-01-01T00:00:00Z"
1818
},

scm/driver/gitea/testdata/webhooks/issue_comment_created.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"Private": true,
1010
"Clone": "http://try.gitea.io/gogits/hello-world.git",
1111
"CloneSSH": "git@localhost:gogits/hello-world.git",
12-
"Link": "",
12+
"Link": "http://try.gitea.io/gogits/hello-world",
1313
"Created": "0001-01-01T00:00:00Z",
1414
"Updated": "0001-01-01T00:00:00Z"
1515
},

scm/driver/gitea/testdata/webhooks/issues_opened.json.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"Private": true,
1010
"Clone": "http://try.gitea.io/gogits/hello-world.git",
1111
"CloneSSH": "git@localhost:gogits/hello-world.git",
12-
"Link": "",
12+
"Link": "http://try.gitea.io/gogits/hello-world",
1313
"Created": "0001-01-01T00:00:00Z",
1414
"Updated": "0001-01-01T00:00:00Z"
1515
},

0 commit comments

Comments
 (0)