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

Add Pull Request support for Bitbucket #597

Open
lazy404 opened this issue Oct 19, 2014 · 26 comments
Open

Add Pull Request support for Bitbucket #597

lazy404 opened this issue Oct 19, 2014 · 26 comments

Comments

@lazy404
Copy link

lazy404 commented Oct 19, 2014

Bitbucket has support for PR hooks

https://confluence.atlassian.com/display/BITBUCKET/Pull+Request+POST+hook+management;jsessionid=3CF795068ED8DB1530108DC91C83ACB0.node2

@bradrydzewski
Copy link

Are there docs for cloning a pull request?

@lazy404
Copy link
Author

lazy404 commented Oct 19, 2014

So far I have found this

https://confluence.atlassian.com/display/BITBUCKET/Pull+Request+POST+hook+management;jsessionid=3CF795068ED8DB1530108DC91C83ACB0.node2

git remote add pr https://pr_source/pr/pr_repo
git fetch pr
git merge pr_hash_from_json

also there is also a link to diff

https://bitbucket.org/api/2.0/repositories/lazy404/drone_test/pullrequests/5/diff

I have found this https://bitbucket.org/site/master/issue/5814/reify-pull-requests-by-making-them-a-ref
so it's only avaiable by api

@bradrydzewski bradrydzewski changed the title Pull request hooks not supported on bitbucket Add Pull Request support for Bitbucket Oct 20, 2014
@bradrydzewski
Copy link

We had someone investigate this about 6 months ago. The details are a bit fuzzy, but I thought the issue was that you need to clone from the fork and merge. This was problematic for private repositories because they use an SSH key to clone, and that SSH key does not grant authorization to the fork.

Again, this is from memory and that was 6 months ago, so it would need more research.

@lazy404
Copy link
Author

lazy404 commented Oct 20, 2014

One can add drone deploy key manually to the PR source repo.

will the following be ok for checking pr request from
git@bitbucket.org:other/drone_test.git with PR_COMMIT hash ?

git clone --depth=50 --recursive --branch=master git@bitbucket.org:lazy404/drone_test.git
git remote add PR git@bitbucket.org:other/drone_test.git
git fetch PR
git merge PR_COMMIT

@bradrydzewski
Copy link

@lazy404 working on pull request support for Bitbucket and GitLab. Would you be willing to weigh-in on the proposed design: #1066

@kushtrimjunuzi
Copy link

Is there any progress with this issue?

@bradrydzewski
Copy link

I'm not aware of anyone working on this at the moment. The issue has been labeled as help wanted, which means it is not something I'm planning on implementing, but would accept a community contribution.

@appleboy
Copy link

appleboy commented Nov 3, 2016

Update correct link for Pull Request POST service management for bitbucket cloud

@bradrydzewski
Copy link

bradrydzewski commented Nov 19, 2016

I just merged #1864 which stores the remote repository for the pull request as well as a refspec value. With these values we can do the following:

# clone base
git clone https://bitbucket.org/atlassianlabs/ac-koa-hipchat
cd ac-koa-hipchat

# clone head from remote repo, refspec version/0.2.20:master
git pull https://bitbucket.org/andrew_sokolov/ac-koa-hipchat version/0.2.20:master

There are still some additional changes that will be required, for which I'm definitely willing to accept pull requests. Note that I'm not planning to work on this, so for those reading, we definitely need your help here.

git clone plugin

We need to alter the git plugin to handle pull requests that don't use merge refs. This would essentially look like the above shell script. Note that I realize it isn't perfect, but it is better than what we have now which is nothing :)

bitbucket hook parser

We need to alter the bitbucket hook parser to enable external pull requests. Right now the bitbucket hook parser only accepts intra-repository pull requests.

@patrickjahns
Copy link

I will try to look into this. Would be great to get this working in order to have a workflow were the pull_request is temporarily merged in the build and then tested.
(It could then lead to writing a bitbucket plugin which automatically approves and merges a pull_request, when it succeeds. A step closer to automation for CI ;-) )

@zaggash
Copy link

zaggash commented Apr 16, 2017

Hi there.
Is there any tips or tricks to make PR build at the moment, before drone support it?
Any jenkins integration or call to drone cli... or something?
Just wondering if I forget something :)

@bradrydzewski bradrydzewski removed this from the Unplanned milestone May 13, 2017
@bradrydzewski bradrydzewski added this to To Do in Version 1.0 Apr 2, 2018
@bradrydzewski bradrydzewski moved this from To Do to In Progress in Version 1.0 Jun 29, 2018
@bradrydzewski bradrydzewski moved this from In Progress to Done in Version 1.0 Jul 27, 2018
@bradrydzewski bradrydzewski added this to the v1.0.0 milestone Jul 30, 2018
@bradrydzewski
Copy link

bradrydzewski commented Nov 4, 2018

Note that this issue is frozen until Bitbucket solves the following issue:
https://bitbucket.org/site/master/issues/5814/repository-refs-for-pull-requests

They recently (in 2018) posted that they are working on this issue, and will rollout a series of changes in phases. Once they have a fix in place we can quickly implement in Drone.

@harness harness locked and limited conversation to collaborators Nov 4, 2018
@bradrydzewski bradrydzewski removed this from the v1.0.0 milestone Nov 4, 2018
@bradrydzewski bradrydzewski removed this from Done in Version 1.0 Nov 4, 2018
@harness harness unlocked this conversation Nov 4, 2018
@dmytro-tolkodubov
Copy link

Hi @bradrydzewski
https://bitbucket.org/site/master/issues/5814/repository-refs-for-pull-requests has been opened 7 years ago, we may wait 7 more until they implement this functionality.
Could you please advise if is somehow possible to trigger the drone build on PR event? We could then just merge develop with the feature branch and run tests on it. Is there any way to do that? Thanks in advance.

@tboerger
Copy link

tboerger commented Apr 8, 2019

Without paying bitbucket customers complaining about it I guess it will never beeing implemented.

@dmytro-tolkodubov
Copy link

@tboerger Hi Thomas, thanks for your reply. That's indeed very sad they can't implement that. Please could you advise if that is ever possible to trigger the build on PR event? Yes, we can't checkout the PR by ref spec, but at least we could do some other manual steps, ie merge feature branch with develop and run tests on it... Currently drone CI seems to ignore PR events from Bitbucket cloud.

@tboerger
Copy link

tboerger commented Apr 8, 2019

I don't know which webhooks are getting sent by Bitbucket.

@dmytro-tolkodubov
Copy link

dmytro-tolkodubov commented Apr 8, 2019 via email

@bradrydzewski
Copy link

bradrydzewski commented Apr 8, 2019

Hooks are not the problem. Without pull request refs we would have to change our clone process, and even with this change there is no guarantee cloning pull requests from private forks would work properly. It is undesirable to change our clone process just for Bitbucket, given that GitHub, GitLab, Gogs, Gitea and even Atlassian Stash all support pull request refs.

@dmytro-tolkodubov
Copy link

dmytro-tolkodubov commented Apr 9, 2019

@bradrydzewski Brad, thank you for your reply. That's a fair point regarding the cloning process. But what if you could just enable steps triggering on PR event, event without cloning PR/merge ref it is going to be a huge benefit for BitBucket clould users as we would be able to execute the steps triggered by this event. Is that possible without changing the clone logic?

@bradrydzewski
Copy link

@dmytro-tolkodubov it is possible, however, the result is that every Bitbucket pull request would fail by default. Drone would be perceived as broken and the resulting support burden would probably decrease my quality of life. I'm not sure I want to take such actions at this time ... although I do appreciate the suggestion.

@kushtrimjunuzi
Copy link

Recently I implemented a workaround and it is working for my workflow, so basically for every PR there is a webhook request and cloning the target branch from upstream as usual but there is a step in pipeline were git rebase with PR, this is private repo and private fork. I dont know if this might help. The contributor has to be in drone users list in order to pull and rebase his/her PR.

pipeline:

  dev_git_pull_pr:
    image: plugins/git
    commands:
      - "git pull --rebase --no-tags https://bitbucket.org/${DRONE_COMMIT_AUTHOR}/${DRONE_REPO_NAME} ${DRONE_COMMIT_REFSPEC}"
    when:
      branch: [master]
      event: [pull_request]

@dmytro-tolkodubov
Copy link

@bradrydzewski, thanks for replying.
@kushtrimjunuzi, are you running drone 1.0? I think pull_requst event handling is not supported for BB cloud. Brad stated this as well above. Also DRONE_COMMIT_REFSPEC does not seems to be available in 1.0 release.

@kushtrimjunuzi
Copy link

@dmytro-tolkodubov I'm running drone 0.8

@kushtrimjunuzi
Copy link

I was able to hack and enable this pull_request flow in drone 1, I know its not the best way and while waiting for bitbucket.org to support pull request. Take a look a fork here
https://github.com/kushtrimjunuzi/drone and here https://github.com/kushtrimjunuzi/go-scm.
Btw in drone 0.8 for some reason pull requests are not parsed correctly, DRONE_COMMIT_AUTHOR is returning empty, I'm guessing this is because of api changes from bitbucket.org, for this reason I was forced to just move to latest drone version and do this hack.

pipeline:
  dev_git_pull_pr:
    image: plugins/git
    commands:
         - "git pull --no-tags https://bitbucket.org/${DRONE_COMMIT_AUTHOR}/${DRONE_REPO_NAME} ${DRONE_SOURCE_BRANCH}:master"
    when:
      branch: [master]
      event: [pull_request]

@dmytro-tolkodubov
Copy link

Nice one! But we decided to move to GitHub and no regrets :)

@puzzloholic
Copy link

@bradrydzewski Everyone who stumble upon this issue would be glad if there is undocumented flag on the yaml to enable pull request Bitbucket trigger, so they don't have to fork the repo just to enable the feature like @kushtrimjunuzi just did. :D
Custom clone step is just perfect for this issue, but it won't happen because the pull request itself cannot trigger the pipeline.

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

No branches or pull requests

9 participants