woodpecker-ci / woodpecker

Woodpecker is a simple yet powerful CI/CD engine with great extensibility.
https://woodpecker-ci.org
Apache License 2.0
3.94k stars 352 forks source link

Enabling Bitbucket repo fails on local docker deployment #1882

Closed mzampetakis closed 1 year ago

mzampetakis commented 1 year ago

Component

server

Describe the bug

I am running a woodpecker:latest on my Mac using docker. I have connected through oAuth to the Bitbucket cloud and all the repos are listed within the UI. Trying to enable any repo (public or private) returns an error:

POST http://[DOMAIN]:[PORT]/api/repos?forge_remote_id={UUID}
--- HTTP 500 ---
Could not fetch repository from forge.

I have tried the same functionality with Github and everything worked fine.

I have seen this issue: https://github.com/woodpecker-ci/woodpecker/issues/143 but in my case I use a DDNS and port forward so that my local instance of woodpecker server can be accessed publicly.

System Info

Woodpecker version: `{"source":"https://github.com/woodpecker-ci/woodpecker","version":"next-eaae6b44"}`

Docker file:

# docker-compose.yml
version: '3'

services:
  woodpecker-server:
    image: woodpeckerci/woodpecker-server:next
    ports:
      - 80:8000
      - 9000:9000
    volumes:
      - woodpecker-server-data:/var/lib/woodpecker/
    environment:
      - WOODPECKER_AUTHENTICATE_PUBLIC_REPOS=true
      - WOODPECKER_OPEN=true
      - WOODPECKER_HOST=${WOODPECKER_HOST}
      # - WOODPECKER_GITHUB=true
      # - WOODPECKER_GITHUB_CLIENT=${WOODPECKER_GITHUB_CLIENT}
      # - WOODPECKER_GITHUB_SECRET=${WOODPECKER_GITHUB_SECRET}
      - WOODPECKER_BITBUCKET=true
      - WOODPECKER_BITBUCKET_CLIENT=${WOODPECKER_BITBUCKET_CLIENT}
      - WOODPECKER_BITBUCKET_SECRET=${WOODPECKER_BITBUCKET_SECRET}
      - WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}

  woodpecker-agent:
    image: woodpeckerci/woodpecker-agent:next
    command: agent
    restart: always
    depends_on:
      - woodpecker-server
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - WOODPECKER_SERVER=woodpecker-server:9000
      - WOODPECKER_AGENT_SECRET=${WOODPECKER_AGENT_SECRET}

volumes:
  woodpecker-server-data:


### Additional context

I am now aware how could I grab any logs from the server.

### Validations

- [X] Read the [Contributing Guidelines](https://github.com/woodpecker-ci/woodpecker/blob/master/CONTRIBUTING.md).
- [X] Read the [docs](https://woodpecker-ci.org/docs/intro).
- [X] Check that there isn't [already an issue](https://github.com/woodpecker-ci/woodpecker/issues) that reports the same bug to avoid creating a duplicate.
- [X] Checked that the bug isn't fixed in the `next` version already [https://woodpecker-ci.org/faq#which-version-of-woodpecker-should-i-use]
- [X] Check that this is a concrete bug. For Q&A join our [Discord Chat Server](https://discord.gg/fcMQqSMXJy) or the [Matrix room](https://matrix.to/#/#woodpecker:matrix.org).
mzampetakis commented 1 year ago

Tried it localhost but using a local domain through ngrok and git the exact same error while trying to Enable a repo from Bitbucket:

Could not fetch repository from forge.
mzampetakis commented 1 year ago

It seems that

func (c *Client) FindRepo(owner, name string) (*Repo, error) 

from Bitbucket forge invokes an non valid URL:

https://api.bitbucket.org/2.0/repositories//{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX}

The owner name is required and at this case is empty.

anbraten commented 1 year ago

Interesting. Should be pretty easy to fix though.

mzampetakis commented 1 year ago

I am looking into this. The most obvious solution is to update the

func (c *Client) FindRepo(owner, name string) (*Repo, error) 

from the bitbucket forge, in order to retrieve all the repos which does not require the owner and the find the owner of the requested repo. Another solution could be to change

func PostRepo(c *gin.Context) { 

from server/api/repo.goin order to send the owner of the repo.