Navigation Menu

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

Strip optional '.git' suffix from https server remote name. #1153

Merged
merged 3 commits into from Mar 31, 2022

Conversation

salexander6
Copy link
Contributor

Fixes an error when creating a PR, similar to what is described here #1096

My repository name was identified as data.git and the .git suffix caused an error when creating the PR here https://github.com/peter-evans/create-pull-request/blob/main/src/github-helper.ts#L47

Determining the base and head repositories
  /usr/bin/git config --local --get remote.origin.url
  https://***@github.com/99spokes/data.git
Create or update the pull request
  Attempting creation of pull request {
    "owner": "99spokes",
    "repo": "data.git",
    "title": "Update Products",
    "head": "99spokes:update-products",
    "base": "main",
    "body": "Automated changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action",
    "draft": false
  }
  Error: Not Found

@peter-evans
Copy link
Owner

Hi @salexander6

Thank you for identifying this issue. I'm interested to know how this occurs so I can reproduce it. Please could you show me a workflow that results in this happening. Perhaps you are not using the official actions/checkout action to checkout the repository?

src/utils.ts Outdated
@@ -46,12 +46,14 @@ export function getRemoteDetail(remoteUrl: string): RemoteDetail {
throw new Error('Could not parse GitHub Server name')
}

remoteUrl = remoteUrl.replace(/\.git$/, '')

const httpsUrlPattern = new RegExp(
'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+)$',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to fix this by only changing the regex.

'^https?://.*@?' + githubServerMatch[1] + '/(.+/.+?)(.git)?$',

Also, please add a test for this pattern here:
https://github.com/peter-evans/create-pull-request/blob/main/__test__/utils.unit.test.ts#L35-L53

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to fix this by only changing the regex.
👍

@salexander6
Copy link
Contributor Author

Please could you show me a workflow that results in this happening. Perhaps you are not using the official actions/checkout action to checkout the repository?

The repo is private but here's the relevant workflow section

steps:
  - name: Check out 99spokes/data
    run: |
      git clone --filter=blob:none --no-checkout https://$BOT_GITHUB_TOKEN@github.com/99spokes/data.git
      cd data
      git sparse-checkout init --cone --sparse-index
      git sparse-checkout set products
      git checkout main
    env:
      BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}

  - name: Download artifacts
    uses: actions/download-artifact@v2
    with:
      name: products
      path: data/products

  - name: Create Pull Request
    uses: 99spokes/create-pull-request@fix-https-repository-name
    with:
      path: data
      token: ${{ secrets.BOT_GITHUB_TOKEN }}
      branch: update-products
      commit-message: Update products.
      title: 'Update Products'
      labels: automerge

Adding this here has me wondering if cloning without the .git extension would work around the issue 🤔

@peter-evans
Copy link
Owner

Ok, it makes sense now. Not using the official checkout action causes the remote URL to include the .git suffix. It's an easy fix though, so I'm happy to get this merged, regardless of whether or not you are able to work around it.

@peter-evans
Copy link
Owner

peter-evans commented Mar 31, 2022

/test repository=99spokes/create-pull-request ref=fix-https-repository-name build=true

Command run output

@peter-evans peter-evans merged commit 15b68d1 into peter-evans:main Mar 31, 2022
@peter-evans
Copy link
Owner

Thank you!

Released as v4.0.1 / v4

@salexander6
Copy link
Contributor Author

Thanks for the great action!

aleksandrychev pushed a commit to aleksandrychev/create-pull-request that referenced this pull request Mar 4, 2024
…er-evans#1153)

* Strip optional '.git' suffix from https server remote name.

* Revert "Strip optional '.git' suffix from https server remote name."

This reverts commit c2e9041.

* Strip optional '.git' suffix from https server remote name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants