-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add gitea remote driver. #2017
Conversation
remote/gitea/gitea_test.go
Outdated
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func Test_gogs(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gitea
remote/gitea/gitea.go
Outdated
client := c.newClientToken(u.Token) | ||
ref := b.Commit | ||
|
||
// TODO gogs does not yet return a sha with the pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gitea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still the case for gitea?
remote/gitea/fixtures/handler.go
Outdated
} `json:"config"` | ||
}{} | ||
c.BindJSON(&in) | ||
if in.Type != "gogs" || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gitea
remote/gitea/fixtures/hooks.go
Outdated
@@ -0,0 +1,140 @@ | |||
package fixtures | |||
|
|||
// Sample Gogs push hook |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gitea
remote/gitea/gitea.go
Outdated
"github.com/drone/drone/model" | ||
"github.com/drone/drone/remote" | ||
|
||
"github.com/go-gitea/go-sdk/gitea" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code.gitea.io/sdk should be the correct import path.
remote/gitea/gitea.go
Outdated
|
||
const ( | ||
DescPending = "the build is pending" | ||
DescRunning = "the buils is running" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
|
||
// Login authenticates an account with Gitea using basic authenticaiton. The | ||
// Gitea account details are returned when the user is successfully authenticated. | ||
func (c *client) Login(res http.ResponseWriter, req *http.Request) (*model.User, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OAuth2 provider is not done yet, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. you are right.
remote/gitea/gitea.go
Outdated
client := c.newClientToken(u.Token) | ||
ref := b.Commit | ||
|
||
// TODO gogs does not yet return a sha with the pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still the case for gitea?
remote/gitea/fixtures/handler.go
Outdated
@@ -79,7 +79,6 @@ const repoPayload = ` | |||
{ | |||
"owner": { | |||
"login": "test_name", | |||
"username": "test_name", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remote/gitea/fixtures/handler.go
Outdated
) | ||
|
||
// Handler returns an http.Handler that is capable of handling a variety of mock | ||
// Bitbucket requests and returning mock responses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gitea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d631966 done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few notes and questions :)
drone/server/server.go
Outdated
EnvVar: "DRONE_GITEA_URL", | ||
Name: "gitea-server", | ||
Usage: "gitea server address", | ||
Value: "https://github.com", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might wanna have https://try.gitea.io
as default instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
remote/gitea/fixtures/handler.go
Outdated
) | ||
|
||
// Handler returns an http.Handler that is capable of handling a variety of mock | ||
// Bitbucket requests and returning mock responses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Bitbucket/Gitea
remote/gitea/gitea.go
Outdated
return gitea.StatusFailure | ||
case model.StatusKilled: | ||
return gitea.StatusFailure | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe have
case model.StatusDesclined:
return gitea.StatusWarning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I'm not sure what StatusDeclined
is actually :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to the gating of drone if the gating have been declined. So I think gitea.StatusWarning makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add model.StatusDeclined
remote/gitea/gitea.go
Outdated
return "", fmt.Errorf("Not Implemented") | ||
} | ||
|
||
// Teams is not supported by the Gitea driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is outdated.
remote/gitea/gitea.go
Outdated
return c.newClientToken(u.Token).GetFile(r.Owner, r.Name, ref, f) | ||
} | ||
|
||
// Status is not supported by the Gitea driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status is supported 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, outdated comment as well :D
remote/gitea/gitea.go
Outdated
"content_type": "json", | ||
} | ||
hook := gitea.CreateHookOption{ | ||
Type: "gogs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gitea
remote/gitea/gitea.go
Outdated
return err | ||
} | ||
|
||
// Deactivate is not supported by the Gitea driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why not? We have delete webhook
no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at my pending pull-request, I have started to integrate that for Gogs some time ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: #1752
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for reference PR #1752
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference PR is only for the Gogs driver, not for Gitea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tboerger Yes. I can create another PR to implement Deactivate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we should implement Deactivate as part of this PR. Without the ability to deactivate, a repository cannot be re-enabled correctly
remote/gitea/helper.go
Outdated
@@ -186,7 +186,7 @@ func parsePullRequest(r io.Reader) (*pullRequestHook, error) { | |||
} | |||
|
|||
// fixMalformedAvatar is a helper function that fixes an avatar url if malformed | |||
// (currently a known bug with gogs) | |||
// (currently a known bug with gitea) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to bug issue?
remote/gitea/gitea.go
Outdated
|
||
"github.com/drone/drone/model" | ||
"github.com/drone/drone/remote" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not on Gitea, drop this empty line :)
remote/gitea/gitea.go
Outdated
return gitea.StatusFailure | ||
case model.StatusKilled: | ||
return gitea.StatusFailure | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to the gating of drone if the gating have been declined. So I think gitea.StatusWarning makes sense.
remote/gitea/gitea.go
Outdated
return "", fmt.Errorf("Not Implemented") | ||
} | ||
|
||
// Teams is not supported by the Gitea driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is outdated.
return teams, nil | ||
} | ||
|
||
// TeamPerm is not supported by the Gitea driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really not supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is no longer used so we can remove from Remote
remote/gitea/gitea.go
Outdated
client := c.newClientToken(u.Token) | ||
ref := b.Commit | ||
|
||
// TODO gitea does not yet return a sha with the pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still valid for Gitea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we send a sha now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update this to include sha?
remote/gitea/gitea.go
Outdated
return c.newClientToken(u.Token).GetFile(r.Owner, r.Name, ref, f) | ||
} | ||
|
||
// Status is not supported by the Gitea driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, outdated comment as well :D
remote/gitea/gitea.go
Outdated
return err | ||
} | ||
|
||
// Deactivate is not supported by the Gitea driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at my pending pull-request, I have started to integrate that for Gogs some time ago.
} | ||
|
||
// fixMalformedAvatar is a helper function that fixes an avatar url if malformed | ||
// (currently a known bug with gitea) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, is that still the case for Gitea?
remote/gitea/parse.go
Outdated
) | ||
|
||
const ( | ||
hookEvent = "X-Gogs-Event" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
X-Gitea-Event? AFAIK we got this as fallback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can create next PR to improvement this event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we need to update Gitea source code first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I thought we already added Gitea there: https://github.com/go-gitea/gitea/blob/master/models/webhook.go#L539-L542
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can improve this with another PR. This PR just support commit status and create the new Gitea driver.
remote/gitea/gitea.go
Outdated
) | ||
|
||
// getStatus is a helper functin that converts a Drone | ||
// status to a GitHub status. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/GitHub/gitea/
remote/gitea/parse.go
Outdated
refTag = "tag" | ||
) | ||
|
||
// parseHook parses a Bitbucket hook from an http.Request request and returns |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Bitbucket/Gitea/
} | ||
return &model.Netrc{ | ||
Login: u.Token, | ||
Password: "x-oauth-basic", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"x-oauth-basic"
?
remote/gitea/gitea_test.go
Outdated
}) | ||
}) | ||
|
||
g.It("Should register repositroy hooks", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"repositroy" => "repository"
remote/gitea/gitea_test.go
Outdated
g.Assert(string(raw)).Equal("{ platform: linux/amd64 }") | ||
}) | ||
|
||
g.It("Should return nil frome send build status", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"frome" => "from"
remote/gitea/gitea.go
Outdated
DescDeclined = "the build was rejected" | ||
) | ||
|
||
// getStatus is a helper functin that converts a Drone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in functin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
Very nice, when this can be merged ?=) |
vendor/vendor.json
Outdated
@@ -7,6 +7,12 @@ | |||
"revision": "" | |||
}, | |||
{ | |||
"checksumSHA1": "Vrt1uoeOOk9fp1aa9d7huQhzexU=", | |||
"path": "code.gitea.io/sdk/gitea", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be github.com/go-gitea/go-sdk
?
when I visit code.gitea.io/sdk/gitea
I don't see any source code (maybe I'm not understanding the UI though). I would not feel comfortable with a dependency that developers cannot trace back to the origin source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, this is the correct import path :). It's simple go get magic:
# curl -sL code.gitea.io/sdk/gitea?go-get=1 | grep code.gitea.io/sdk
<meta name="go-import" content="code.gitea.io/sdk git https://github.com/go-gitea/go-sdk">
<meta name="go-source" content="code.gitea.io/sdk https://github.com/go-gitea/go-sdk https://github.com/go-gitea/go-sdk/tree/master{/dir} https://github.com/go-gitea/go-sdk/blob/master{/dir}/{file}#L{line}">
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to give you more background information: We introduced a custom import path directly at the beginning to be able to switch to dog-fooding at some point without distroying previous installs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two minor comments and then I think we can get this merged. I am going to cut an 0.7 tag end of week and it would be great to get this included :)
remote/gitea/gitea.go
Outdated
client := c.newClientToken(u.Token) | ||
ref := b.Commit | ||
|
||
// TODO gitea does not yet return a sha with the pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update this to include sha?
remote/gitea/gitea.go
Outdated
return err | ||
} | ||
|
||
// Deactivate is not supported by the Gitea driver. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we should implement Deactivate as part of this PR. Without the ability to deactivate, a repository cannot be re-enabled correctly
82f4efa
to
7641092
Compare
@bradrydzewski @lunny @bkcsoft @tboerger @DblK I already finished the implements of |
Signed-off-by: Bo-Yi Wu <[email protected]>
Signed-off-by: Bo-Yi Wu <[email protected]>
Signed-off-by: Bo-Yi Wu <[email protected]>
Signed-off-by: Bo-Yi Wu <[email protected]>
Signed-off-by: Bo-Yi Wu <[email protected]>
Signed-off-by: Bo-Yi Wu <[email protected]>
Signed-off-by: Bo-Yi Wu <[email protected]>
Signed-off-by: Bo-Yi Wu <[email protected]>
which release of Drone will first have this support ? |
@strk I guess the 1.2 version. |
I mean Drone version - latest is 0.8 |
@strk 0.7 version |
Since Gitea already supports status API. go-gitea/gitea#1332 It is time to create a new remote driver for Gitea.
cc @tboerger @lunny @bkcsoft
ref: #1978