qbicsoftware-archive / qube-cli

Collection of QBiC's internal project templates
MIT License
3 stars 0 forks source link

Recent Github changes break project creation Github support #233

Open Zethson opened 3 years ago

Zethson commented 3 years ago

Another friendly public service announcement haha

I got a couple of reports, where the initial pushes to master failed for the following reasons:

  1. Pushing Github workflows automatically may require that the Token has workflow permissions. This happened suddenly and I don't know the reason for it.
  2. Github introduced renaming of the main branches and set main as default. I reverted mine back to master, but not everyone at QBiC may do so.

However, pushes to Github always assume that there is a master branch, which may no longer be the case.

Fixes for the issues:

  1. Ensure that your token has workflow permissions. Update yours with qube config pat
  2. Replace the pushes to master in github_support.py with
        # some descriptive comment
        headers = {'Authorization': f'token {access_token}'}
        url = f"https://api.github.com/repos/{creator_ctx.github_username}/{creator_ctx.project_slug}"
        response = requests.get(url, headers=headers).json()
        default_branch = response['default_branch']
        log.debug(f'git push origin {default_branch}')
        print(f'[bold blue]Pushing template to Github origin {default_branch}')
        if default_branch != 'master':
            cloned_repo.git.branch('-M', f'{default_branch}')
        cloned_repo.remotes.origin.push(refspec=f'{default_branch}:{default_branch}')

Reflect this change with the branch protection a little bit below where master is hardcoded and change that to f'{default_branch}'

Cheers

Zethson commented 3 years ago

For reference:

https://github.com/mlf-core/mlf-core/commit/8cd90e782b189b6d7e9ee0643df9225b7fa69c4b