dspinellis/git-issue

Inconsistent argument letter case handling

Closed this issue · 1 comments

The import-export.sh script allows issues to be synchronised with the trackers in GitHub and GitLab. The current syntax for importing and exporting are as follows:

git issue import "$provider" "$user" "$repo"
git issue export "$provider" "$user" "$repo"

Expected Behavior

It is expected, or at least I expect it, to work regardless of the letter case of the values of $user and $repo, as long as it is consistent.

Current Behavior

Currently, it determines the repository and the user name of repository owner using command line arguments as above. However, these arguments are converted to lower case when importing, but uses the given arguments directly when exporting. This means, importing creates metadata using lower case, but exporting may not be able find the same metadata.

Possible Solution

Decide on a letter case handling strategy, and use it for all credential parsing.

Steps to Reproduce

The following is an example usage that may fail. It passes in $user and $repo in mixed case.

  1. Setup the repo. Not necessary, but it is a common setup?

    $ git clone 'https://github.com/BoniLindsley/git-issue_TestRepo.git'
    Cloning into 'git-issue_TestRepo'...
    remote: Enumerating objects: 3, done.
    remote: Counting objects: 100% (3/3), done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    Unpacking objects: 100% (3/3), 643 bytes | 643.00 KiB/s, done.
    $ cd 'git-issue_TestRepo'
    
  2. Import issue(s) from GitHub.

    $ git issue init
    Initialized empty issues repository in /home/boni/git-issue_TestRepo/.issues
    $ export GH_CURL_AUTH="Authorization: token 4edac7ed0beef0cafe0dead0face0c4edec71a15"
    $ git issue import github BoniLindsley git-issue_TestRepo
    Imported/updated issue #1 as a38d0e9
    $ ls .issues/imports/github/bonilindsley
    git-issue_testrepo
    
  3. Try to check for updates to export. The script is unable to find the newly created metadata.

    $ git issue import github BoniLindsley git-issue_TestRepo
    No local issues found for this repository.
    

Context (Environment)

I am currently testing out these scripts on Debian bullseye/sid. Basic usage seems to be fine, except for this letter case issue. I suspect this cannot be replicated on Windows.

Detailed Description

I think converting usernames and repository names to lower case does make sense in that they are case insensitive in GitHub and GitLab. Making sure that lower case conversion is used everywhere should suffice.

Not converting to lower case is also an option, as long as it is consistent.

It might be prudent to decide whether $provider requires the same treatment as well.

Possible Implementation

I believe it is just a matter of search and replace on user, repo and possibly provider. It is debatable whether letter case conversion should be pulled into a function.

#!/bin/sh

convert_to_lower_case()
{
  echo "$1" | tr '[:upper:]' '[:lower:]'
}

gi_export()
{
  local provider user repo
  provider="$(convert_to_lower_case $1)"
  user="$(convert_to_lower_case $2)"
  repo="$(convert_to_lower_case $3)"
  echo "Provider: $provider"
  echo "Username: $user"
  echo "Repository: $repo"
}

gi_export GitHub BoniLindsley git-issue_TestRepo

Thank you so much for the exemplary detailed description! I'd welcome a pull request along the lines of the possible implementation you describe.