Skip to content
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

Merged
merged 17 commits into from
May 24, 2017
Merged

feat: add gitea remote driver. #2017

merged 17 commits into from
May 24, 2017

Conversation

appleboy
Copy link

@appleboy appleboy commented May 1, 2017

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

"github.com/gin-gonic/gin"
)

func Test_gogs(t *testing.T) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gitea

client := c.newClientToken(u.Token)
ref := b.Commit

// TODO gogs does not yet return a sha with the pull request
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitea

Copy link

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?

} `json:"config"`
}{}
c.BindJSON(&in)
if in.Type != "gogs" ||
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitea

@@ -0,0 +1,140 @@
package fixtures

// Sample Gogs push hook
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gitea

"github.com/drone/drone/model"
"github.com/drone/drone/remote"

"github.com/go-gitea/go-sdk/gitea"
Copy link

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.


const (
DescPending = "the build is pending"
DescRunning = "the buils is running"
Copy link

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) {
Copy link

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. you are right.

client := c.newClientToken(u.Token)
ref := b.Commit

// TODO gogs does not yet return a sha with the pull request
Copy link

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?

@appleboy
Copy link
Author

appleboy commented May 1, 2017

@tboerger @lunny just fix testing first.

@@ -79,7 +79,6 @@ const repoPayload = `
{
"owner": {
"login": "test_name",
"username": "test_name",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

// Handler returns an http.Handler that is capable of handling a variety of mock
// Bitbucket requests and returning mock responses.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitea

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d631966 done

Copy link

@bkcsoft bkcsoft left a 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 :)

EnvVar: "DRONE_GITEA_URL",
Name: "gitea-server",
Usage: "gitea server address",
Value: "https://github.com",
Copy link

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

)

// Handler returns an http.Handler that is capable of handling a variety of mock
// Bitbucket requests and returning mock responses.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Bitbucket/Gitea :trollface:

return gitea.StatusFailure
case model.StatusKilled:
return gitea.StatusFailure
default:
Copy link

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

Copy link

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 :)

Copy link

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add model.StatusDeclined

return "", fmt.Errorf("Not Implemented")
}

// Teams is not supported by the Gitea driver.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? 😄

Copy link

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 c.newClientToken(u.Token).GetFile(r.Owner, r.Name, ref, f)
}

// Status is not supported by the Gitea driver.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Status is supported 😉

Copy link

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

"content_type": "json",
}
hook := gitea.CreateHookOption{
Type: "gogs",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gitea

return err
}

// Deactivate is not supported by the Gitea driver.
Copy link

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?

Copy link

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: #1752

Copy link
Author

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

Copy link

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.

Copy link
Author

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.

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

@@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link to bug issue?


"github.com/drone/drone/model"
"github.com/drone/drone/remote"

Copy link

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 :)

return gitea.StatusFailure
case model.StatusKilled:
return gitea.StatusFailure
default:
Copy link

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.

return "", fmt.Errorf("Not Implemented")
}

// Teams is not supported by the Gitea driver.
Copy link

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.
Copy link

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?

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

client := c.newClientToken(u.Token)
ref := b.Commit

// TODO gitea does not yet return a sha with the pull request
Copy link

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?

Copy link

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 :)

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?

return c.newClientToken(u.Token).GetFile(r.Owner, r.Name, ref, f)
}

// Status is not supported by the Gitea driver.
Copy link

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

return err
}

// Deactivate is not supported by the Gitea driver.
Copy link

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)
Copy link

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?

)

const (
hookEvent = "X-Gogs-Event"
Copy link

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.

Copy link
Author

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.

Copy link
Author

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.

Copy link

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

Copy link
Author

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.

@lunny lunny mentioned this pull request May 2, 2017
20 tasks
)

// getStatus is a helper functin that converts a Drone
// status to a GitHub status.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/GitHub/gitea/

refTag = "tag"
)

// parseHook parses a Bitbucket hook from an http.Request request and returns
Copy link

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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"x-oauth-basic" ?

})
})

g.It("Should register repositroy hooks", func() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"repositroy" => "repository"

g.Assert(string(raw)).Equal("{ platform: linux/amd64 }")
})

g.It("Should return nil frome send build status", func() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"frome" => "from"

DescDeclined = "the build was rejected"
)

// getStatus is a helper functin that converts a Drone
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in functin

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

@vtolstov
Copy link

Very nice, when this can be merged ?=)

@@ -7,6 +7,12 @@
"revision": ""
},
{
"checksumSHA1": "Vrt1uoeOOk9fp1aa9d7huQhzexU=",
"path": "code.gitea.io/sdk/gitea",

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.

Copy link

@tboerger tboerger May 22, 2017

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}">

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Copy link

@bradrydzewski bradrydzewski left a 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 :)

client := c.newClientToken(u.Token)
ref := b.Commit

// TODO gitea does not yet return a sha with the pull request

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?

return err
}

// Deactivate is not supported by the Gitea driver.

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

@appleboy appleboy force-pushed the gitea branch 2 times, most recently from 82f4efa to 7641092 Compare May 24, 2017 02:02
@appleboy
Copy link
Author

appleboy commented May 24, 2017

@bradrydzewski @lunny @bkcsoft @tboerger @DblK

7641092

I already finished the implements of deactivate and refactor the file method finally. Please help to review again and make sure you need to update some changes from go-gitea/gitea#1755 before testing this PR.

@bradrydzewski bradrydzewski merged commit 85c8627 into harness:master May 24, 2017
@appleboy appleboy deleted the gitea branch May 24, 2017 14:27
@strk
Copy link

strk commented Jan 19, 2018

which release of Drone will first have this support ?

@appleboy
Copy link
Author

@strk I guess the 1.2 version.

@strk
Copy link

strk commented Jan 20, 2018

I mean Drone version - latest is 0.8

@appleboy
Copy link
Author

@strk 0.7 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants