Skip to content

Commit

Permalink
simplify git issue import functionality
Browse files Browse the repository at this point in the history
allow git issue import to work without arguments for origin repo
but also allow you to define the remote if 1 arguement is present
  • Loading branch information
Frazer Clews committed Aug 2, 2020
1 parent aac4c98 commit 5e96621
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions lib/git-issue/import-export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
usage_import()
{
cat <<\USAGE_import_EOF
gi import usage: git issue import provider user repo
gi import usage: git issue import [remote | provider [user [repo]]]
Example: git issue import github torvalds linux
USAGE_import_EOF
exit 2
Expand Down Expand Up @@ -878,16 +878,58 @@ t again
' "$1"-header
}

# Returns the git's repository URL
get_url()
{
local remote=$1

if [ -z "${remote}" ]
then
remote="origin"
fi

local url provider user repo
url=$(git remote get-url ${remote} 2>&1)

if [ "${url}" = "fatal: No such remote '${remote}'" ]
then
printf "%s\n\n" "${url}"
usage_import
fi
echo "${url}"
}

# Returns the git's repository provider name from the URL
get_provider()
{
echo "$1" | grep -oP "(?<=@).*?(?=\.)"
}
# Returns the git's repository user name from the URL
get_user()
{
echo "$1" | grep -oP "(?<=:).*?(?=/)"
}
# Returns the git's repository repo name from the URL
get_repo()
{
echo "$1" | grep -oP "(?<=/).*?(?=.git)"
}

# Import issues from specified source (currently github and gitlab)
sub_import()
{
local endpoint user repo begin_sha provider
local endpoint user repo begin_sha provider url

test "$1" = github -o "$1" = gitlab -a -n "$2" -a -n "$3" || usage_import
provider="$1"
# convert to lowercase to avoid duplicates
user="$(echo "$2" | tr '[:upper:]' '[:lower:]')"
repo="$(echo "$3" | tr '[:upper:]' '[:lower:]')"
test "$1" = github -o "$1" = gitlab -a -n "$2" -a -n "$3" ||
url=$(get_url "$1"); echo "${url}"; provider=$(get_provider "${url}"); user=$(get_user "${url}"); repo=$(get_repo "${url}")
if ! test -n "${provider}" && ! test -n "${user}" && ! test -n "${repo}"
then
provider="$1"

# convert to lowercase to avoid duplicates
user="$(echo "$2" | tr '[:upper:]' '[:lower:]')"
repo="$(echo "$3" | tr '[:upper:]' '[:lower:]')"
fi

cdissues

Expand Down

0 comments on commit 5e96621

Please sign in to comment.