vsoch / pull-request-action

open a pull request when a branch is pushed or updated
https://github.com/marketplace/actions/pull-request-action
MIT License
174 stars 62 forks source link

find_default_branch getting 401 in Github Enterprise #87

Closed ohenak closed 2 years ago

ohenak commented 2 years ago

We are on Github Enterprise 3.3, when the find_default_branch is invoked, It gets the following error:

Unable to retrieve default branch: 401: Unauthorized
[26](https://github.braintreeps.com/venmo/mobile-release-ios/runs/6575890?check_suite_focus=true#step:5:26)
 {'message': 'Must authenticate to access this API.', 'documentation_url': 'https://docs.github.com/enterprise/3.3/rest'}

It is because the initial Get request does not incorporate the token. https://github.com/vsoch/pull-request-action/blob/master/pull-request.py#L239-L243

    response = requests.get(REPO_URL)

    # Case 1: 404 might need a token
    if response.status_code == 404:
        response = requests.get(REPO_URL, headers=HEADERS)
ohenak commented 2 years ago

Do you prefer handling 404 and 401 in the if statement? Or always include the headers from the first Get request?

vsoch commented 2 years ago

Ah we can add that! Would you care to PR and bump the version?

vsoch commented 2 years ago

Fixed by #88. Thank you!