gabrie30 / ghorg

Quickly clone an entire org/users repositories into one directory - Supports GitHub, GitLab, Bitbucket, and more 🐇🥚
Apache License 2.0
1.58k stars 167 forks source link

ghorg clone with BitBucket PAT (HTTP Access Token) fails #464

Closed keithly closed 3 weeks ago

keithly commented 4 weeks ago

Please check the following resources before opening an issue

  1. Review the troubelshooting section in the README.md
  2. Review the examples directory for example commands

Describe the bug

Providing a BitBucket PAT (now called HTTP Access Token) to the clone command ghorg clone workspace -token=REDACTED results in the error message

Could not find bitbucket username. GHORG_BITBUCKET_USERNAME or (--bitbucket-username) must be set to clone repos from bitbucket, see 'BitBucket Setup' in README.md

The docs say not to provide a BitBucket username when using a token. If a username is provided, then ghorg clone fails with the error message about not having an app password set, as expected from the docs.

The BitBucket instance is self-hosted. ghorg is being run on Windows 10, but from within Git Bash. ghorg is v1.11.0

To Reproduce

GHORG_DEBUG=true ghorg clone workspace -token=REDACTED
-------- Setting Default ENV values ---------
Setting concurrency to 1, this can be overwritten by setting GHORG_CONCURRENCY_DEBUG; however when using concurrency with GHORG_DEBUG, not all debugging output will be printed in serial order.
GHORG_ABSOLUTE_PATH_TO_CLONE_TO: /c/Users/REDACTED/code\
GHORG_BRANCH:
GHORG_CLONE_PROTOCOL: https
GHORG_CLONE_TYPE: org
GHORG_SCM_TYPE: bitbucket
GHORG_PRESERVE_SCM_HOSTNAME: true
GHORG_SKIP_ARCHIVED: false
GHORG_SKIP_FORKS: false
GHORG_NO_CLEAN: true
GHORG_NO_TOKEN: false
GHORG_NO_DIR_SIZE: false
GHORG_FETCH_ALL: false
GHORG_PRUNE: false
GHORG_PRUNE_NO_CONFIRM: false
GHORG_PRUNE_UNTOUCHED: false
GHORG_PRUNE_UNTOUCHED_NO_CONFIRM: false
GHORG_DRY_RUN: true
GHORG_GITHUB_USER_OPTION: owner
GHORG_CLONE_WIKI: false
GHORG_CLONE_SNIPPETS: false
GHORG_INSECURE_GITLAB_CLIENT: false
GHORG_INSECURE_GITEA_CLIENT: false
GHORG_BACKUP: false
GHORG_RECLONE_ENV_CONFIG_ONLY: false
GHORG_RECLONE_QUIET: false
GHORG_CONCURRENCY: 1
GHORG_INCLUDE_SUBMODULES: false
GHORG_EXIT_CODE_ON_CLONE_INFOS: 0
GHORG_EXIT_CODE_ON_CLONE_ISSUES: 1
GHORG_STATS_ENABLED: false
GHORG_CRON_TIMER_MINUTES: 60
GHORG_RECLONE_SERVER_PORT: :8080
GHORG_TARGET_REPOS_PATH:
GHORG_CLONE_DEPTH:
GHORG_GITHUB_TOKEN:
GHORG_GITHUB_TOKEN_FROM_GITHUB_APP: false
GHORG_GITHUB_FILTER_LANGUAGE:
GHORG_TOPICS:
GHORG_GITLAB_TOKEN:
GHORG_BITBUCKET_USERNAME:
GHORG_BITBUCKET_APP_PASSWORD:
GHORG_BITBUCKET_OAUTH_TOKEN: REDACTED
GHORG_SCM_BASE_URL: https://REDACTED.REDACTED.com/
GHORG_PRESERVE_DIRECTORY_STRUCTURE: false
GHORG_OUTPUT_DIR:
GHORG_MATCH_REGEX:
GHORG_EXCLUDE_MATCH_REGEX:
GHORG_MATCH_PREFIX:
GHORG_EXCLUDE_MATCH_PREFIX:
GHORG_GITLAB_GROUP_EXCLUDE_MATCH_REGEX:
GHORG_IGNORE_PATH: C:\Users\REDACTED\.config\ghorg\ghorgignore
GHORG_RECLONE_PATH: C:\Users\REDACTED\.config\ghorg\reclone.yaml
GHORG_QUIET: false
GHORG_GIT_FILTER:
GHORG_GITEA_TOKEN:
GHORG_INSECURE_GITEA_CLIENT: false
GHORG_GITHUB_APP_PEM_PATH:
GHORG_GITHUB_APP_INSTALLATION_ID:
GHORG_GITHUB_APP_ID:
Aliases:
map[string]string{}
Override:
map[string]interface {}{}
PFlags:
map[string]viper.FlagValue{"color":viper.pflagValue{flag:(*pflag.Flag)(0xc0001115e0)}, "config":viper.pflagValue{flag:(*pflag.Flag)(0xc000111680)}}
Env:
map[string][]string{}
Key/Value Store:
map[string]interface {}{}
Config:
map[string]interface {}{"ghorg_absolute_path_to_clone_to":"/c/Users/REDACTED/code", "ghorg_backup":false, "ghorg_bitbucket_oauth_token":"REDACTED", "ghorg_clone_type":"org", "ghorg_color":"enabled", "ghorg_concurrency":25, "ghorg_cron_timer_minutes":"60", "ghorg_debug":true, "ghorg_dry_run":true, "ghorg_exit_code_on_clone_infos":0, "ghorg_exit_code_on_clone_issues":1, "ghorg_git_filter":interface {}(nil), "ghorg_include_submodules":false, "ghorg_no_clean":true, "ghorg_no_dir_size":false, "ghorg_no_token":false, "ghorg_preserve_scm_hostname":true, "ghorg_prune":false, "ghorg_prune_no_confirm":false, "ghorg_prune_untouched":false, "ghorg_prune_untouched_no_confirm":false, "ghorg_reclone_quiet":false, "ghorg_reclone_server_port":":8080", "ghorg_scm_base_url":"https://REDACTED.REDACTED.com", "ghorg_scm_type":"bitbucket", "ghorg_stats_enabled":false}
Defaults:
map[string]interface {}{"config":"C:\\Users\\REDACTED\\.config\\ghorg\\conf.yaml"}
Viper config file used: C:\Users\REDACTED\.config\ghorg\conf.yaml
GHORG_CONFIG SET TO: C:\Users\REDACTED\.config\ghorg\conf.yaml
Could not find bitbucket username. GHORG_BITBUCKET_USERNAME or (--bitbucket-username) must be set to clone repos from bitbucket, see 'BitBucket Setup' in README.md
  1. Details on the user/org you tried to clone e.g. is it your user, a public org, etc.

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context Add any other context about the problem here.

gabrie30 commented 3 weeks ago

Thanks for raising this. I don't have a way to test hosted bitbucket instances currently so bear with me.

However based on the command you are using you'll need to use this flag --base-url=https://my.self.hosted.bitbucket.instance.com

Additionally, I'm going to merge a PR with a potential fix. Are you able to build the latest version off the main branch to test?

gabrie30 commented 3 weeks ago

I looked more into this and the bitbucket library that is used does not support the bitbucket 1.0 api, which is the current implementation for the hosted version. So unfortunately this won't work until the api is updated.