Skip to content

Instantly share code, notes, and snippets.

@AlbinoDrought
Last active June 12, 2019 00:21
Show Gist options
  • Save AlbinoDrought/6751afb1cf6ae36fc8cddbe38b0be015 to your computer and use it in GitHub Desktop.
Save AlbinoDrought/6751afb1cf6ae36fc8cddbe38b0be015 to your computer and use it in GitHub Desktop.
Drone 0.8 Bitbucket Fix "cannot find .drone.yml in refs/heads"

Drone 0.8 Bitbucket 1.0 Deprecation Fix

Download the diff to bitbucket-file-dl.diff after cloning

Applying directly into goroot:

go get -u github.com/drone/drone
cd $GOPATH/src/github.com/drone/drone
git fetch --all
git checkout v0.8.10

# the file from gist
git apply bitbucket-file-dl.diff

go build -ldflags '-extldflags "-static" -X github.com/drone/drone/version.VersionDev=build.'${DRONE_BUILD_NUMBER} -o release/drone-server github.com/drone/drone/cmd/drone-server

docker build -t albinodrought/drone .
diff --git a/build-docker.sh b/build-docker.sh
new file mode 100755
index 0000000..3477bde
--- /dev/null
+++ b/build-docker.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+docker build -t albinodrought/drone .
+docker push albinodrought/drone
+
diff --git a/remote/bitbucket/fixtures/handler.go b/remote/bitbucket/fixtures/handler.go
index f056599..0060f4d 100644
--- a/remote/bitbucket/fixtures/handler.go
+++ b/remote/bitbucket/fixtures/handler.go
@@ -30,7 +30,7 @@ func Handler() http.Handler {
e.POST("/site/oauth2/access_token", getOauth)
e.GET("/2.0/repositories/:owner/:name", getRepo)
e.GET("/2.0/repositories/:owner/:name/hooks", getRepoHooks)
- e.GET("/1.0/repositories/:owner/:name/src/:commit/:file", getRepoFile)
+ e.GET("/2.0/repositories/:owner/:name/src/:commit/:file", getRepoFile)
e.DELETE("/2.0/repositories/:owner/:name/hooks/:hook", deleteRepoHook)
e.POST("/2.0/repositories/:owner/:name/hooks", createRepoHook)
e.POST("/2.0/repositories/:owner/:name/commit/:commit/statuses/build", createRepoStatus)
diff --git a/remote/bitbucket/internal/client.go b/remote/bitbucket/internal/client.go
index 71ea12a..b0cc0e3 100644
--- a/remote/bitbucket/internal/client.go
+++ b/remote/bitbucket/internal/client.go
@@ -19,6 +19,7 @@ import (
"encoding/json"
"fmt"
"io"
+ "io/ioutil"
"net/http"
"net/url"
@@ -42,7 +43,7 @@ const (
pathRepos = "%s/2.0/repositories/%s?%s"
pathHook = "%s/2.0/repositories/%s/%s/hooks/%s"
pathHooks = "%s/2.0/repositories/%s/%s/hooks?%s"
- pathSource = "%s/1.0/repositories/%s/%s/src/%s/%s"
+ pathSource = "%s/2.0/repositories/%s/%s/src/%s/%s"
pathStatus = "%s/2.0/repositories/%s/%s/commit/%s/statuses/build"
)
@@ -144,7 +145,7 @@ func (c *Client) DeleteHook(owner, name, id string) error {
func (c *Client) FindSource(owner, name, revision, path string) (*Source, error) {
out := new(Source)
uri := fmt.Sprintf(pathSource, c.base, owner, name, revision, path)
- err := c.do(uri, get, nil, out)
+ err := c.hackDoSource(uri, get, out)
return out, err
}
@@ -169,6 +170,48 @@ func (c *Client) GetPermission(fullName string) (*RepoPerm, error) {
}
}
+func (c *Client) hackDoSource(rawurl, method string, out *Source) error {
+ uri, err := url.Parse(rawurl)
+ if err != nil {
+ return err
+ }
+
+ // if we are posting or putting data, we need to
+ // write it to the body of the request.
+ var buf io.ReadWriter
+
+ // creates a new http request to bitbucket.
+ req, err := http.NewRequest(method, uri.String(), buf)
+ if err != nil {
+ return err
+ }
+
+ resp, err := c.Do(req)
+ if err != nil {
+ return err
+ }
+ defer resp.Body.Close()
+
+ // if an error is encountered, parse and return the
+ // error response.
+ if resp.StatusCode > http.StatusPartialContent {
+ err := Error{}
+ json.NewDecoder(resp.Body).Decode(&err)
+ err.Status = resp.StatusCode
+ return err
+ }
+
+ // if a json response is expected, parse and return
+ // the json response.
+ if out != nil {
+ hack, err := ioutil.ReadAll(resp.Body)
+ out.Data = string(hack)
+ return err
+ }
+
+ return nil
+}
+
func (c *Client) do(rawurl, method string, in, out interface{}) error {
uri, err := url.Parse(rawurl)
6/11/2019 12:02:45 PMERRO[94252] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/bugfix/stuff: Resource removed
6/11/2019 12:02:45 PMERRO[94252] Error #01: Resource removed
6/11/2019 12:02:45 PM ip=18.234.32.228 latency=11.490893525s method=POST path=/hook status=404 time=2019-06-11T19:02:45Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 12:07:35 PMINFO: 2019/06/11 19:07:35 transport: http2Server.HandleStreams failed to read frame: read tcp 10.42.169.27:9000->10.42.242.50:38976: read: connection reset by peer
6/11/2019 12:13:42 PMERRO[94908] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/store-integration-zed: Resource removed
6/11/2019 12:13:42 PMERRO[94908] Error #01: Resource removed
6/11/2019 12:13:42 PM ip=18.234.32.228 latency=11.60139123s method=POST path=/hook status=404 time=2019-06-11T19:13:42Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 12:18:14 PMINFO: 2019/06/11 19:18:14 transport: http2Server.HandleStreams failed to read frame: read tcp 10.42.169.27:9000->10.42.96.15:46534: read: no route to host
6/11/2019 12:47:03 PMERRO[96910] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/style/animate: Resource removed
6/11/2019 12:47:03 PMERRO[96910] Error #01: Resource removed
6/11/2019 12:47:03 PM ip=18.234.32.226 latency=11.811559892s method=POST path=/hook status=404 time=2019-06-11T19:47:03Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 12:48:07 PMERRO[96974] error: albinodrought/some-project: cannot find .drone.yml in refs/heads/master: Resource removed
6/11/2019 12:48:07 PMERRO[96974] Error #01: Resource removed
6/11/2019 12:48:07 PM ip=18.234.32.224 latency=10.759290179s method=POST path=/hook status=404 time=2019-06-11T19:48:07Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 12:54:09 PMERRO[97335] error: albinodrought/some-other-other-project: cannot find .drone.yml in refs/heads/mm: Resource removed
6/11/2019 12:54:09 PMERRO[97335] Error #01: Resource removed
6/11/2019 12:54:09 PM ip=18.234.32.224 latency=11.403432538s method=POST path=/hook status=404 time=2019-06-11T19:54:09Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 1:31:02 PMERRO[99548] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/feature/required-labels: Resource removed
6/11/2019 1:31:02 PMERRO[99548] Error #01: Resource removed
6/11/2019 1:31:02 PM ip=18.234.32.226 latency=22.266837566s method=POST path=/hook status=404 time=2019-06-11T20:31:02Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 2:10:32 PMERRO[101919] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/store-integration-zed: Resource removed
6/11/2019 2:10:32 PMERRO[101919] Error #01: Resource removed
6/11/2019 2:10:32 PM ip=18.234.32.226 latency=11.390276404s method=POST path=/hook status=404 time=2019-06-11T21:10:32Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 2:17:27 PMERRO[102333] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/bugfix/stuff: Resource removed
6/11/2019 2:17:27 PMERRO[102333] Error #01: Resource removed
6/11/2019 2:17:27 PM ip=18.234.32.226 latency=11.515400735s method=POST path=/hook status=404 time=2019-06-11T21:17:27Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 2:18:21 PMERRO[102388] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/store-integration-zed: Resource removed
6/11/2019 2:18:21 PMERRO[102388] Error #01: Resource removed
6/11/2019 2:18:21 PM ip=18.234.32.226 latency=10.671248669s method=POST path=/hook status=404 time=2019-06-11T21:18:21Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 2:18:51 PMERRO[102418] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/master: Resource removed
6/11/2019 2:18:51 PMERRO[102418] Error #01: Resource removed
6/11/2019 2:18:51 PM ip=18.234.32.228 latency=10.755493438s method=POST path=/hook status=404 time=2019-06-11T21:18:51Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 2:23:22 PMERRO[102688] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/store-integration-zed: Resource removed
6/11/2019 2:23:22 PMERRO[102688] Error #01: Resource removed
6/11/2019 2:23:22 PM ip=18.234.32.224 latency=11.432105662s method=POST path=/hook status=404 time=2019-06-11T21:23:22Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 2:31:10 PMERRO[103157] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/style/animate: Resource removed
6/11/2019 2:31:10 PMERRO[103157] Error #01: Resource removed
6/11/2019 2:31:10 PM ip=18.234.32.228 latency=11.514079164s method=POST path=/hook status=404 time=2019-06-11T21:31:10Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 2:52:45 PMERRO[104452] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/refactor/ticket: Resource removed
6/11/2019 2:52:45 PMERRO[104452] Error #01: Resource removed
6/11/2019 2:52:45 PM ip=18.234.32.224 latency=11.531676565s method=POST path=/hook status=404 time=2019-06-11T21:52:45Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 3:02:11 PMERRO[105018] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/store-integration-zed: Resource removed
6/11/2019 3:02:11 PMERRO[105018] Error #01: Resource removed
6/11/2019 3:02:11 PM ip=18.234.32.228 latency=11.445404227s method=POST path=/hook status=404 time=2019-06-11T22:02:11Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 3:15:53 PMERRO[105840] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/bugfix/stuff: Resource removed
6/11/2019 3:15:53 PMERRO[105840] Error #01: Resource removed
6/11/2019 3:15:53 PM ip=18.234.32.228 latency=11.674123792s method=POST path=/hook status=404 time=2019-06-11T22:15:53Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 3:19:17 PMERRO[106043] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/master: Resource removed
6/11/2019 3:19:17 PMERRO[106043] Error #01: Resource removed
6/11/2019 3:19:17 PM ip=18.234.32.228 latency=11.933742693s method=POST path=/hook status=404 time=2019-06-11T22:19:17Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 3:21:16 PMERRO[106162] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/master: Resource removed
6/11/2019 3:21:16 PMERRO[106162] Error #01: Resource removed
6/11/2019 3:21:16 PM ip=18.234.32.226 latency=11.095885228s method=POST path=/hook status=404 time=2019-06-11T22:21:16Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 3:25:56 PMERRO[106442] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/test: Resource removed
6/11/2019 3:25:56 PMERRO[106442] Error #01: Resource removed
6/11/2019 3:25:56 PM ip=18.234.32.228 latency=11.501792669s method=POST path=/hook status=404 time=2019-06-11T22:25:56Z user-agent=Bitbucket-Webhooks/2.0
6/11/2019 3:26:46 PMERRO[106493] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/test: Resource removed
6/11/2019 3:26:46 PMERRO[106493] Error #01: Resource removed
6/11/2019 3:26:46 PM ip=172.16.30.108 latency=10.661417141s method=POST path=/hook status=404 time=2019-06-11T22:26:46Z user-agent=PostmanRuntime/7.1.1
6/11/2019 3:29:36 PMERRO[106663] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/test: Resource removed
6/11/2019 3:29:36 PMERRO[106663] Error #01: Resource removed
6/11/2019 3:29:36 PM ip=172.16.30.108 latency=10.668200557s method=POST path=/hook status=404 time=2019-06-11T22:29:36Z user-agent=PostmanRuntime/7.1.1
6/11/2019 3:30:43 PMERRO[106730] error: albinodrought/some-other-project: cannot find .drone.yml in refs/heads/test: Resource removed
6/11/2019 3:30:43 PMERRO[106730] Error #01: Resource removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment