Skip to content

Commit

Permalink
Merge pull request #56 from hwixley/feature/wyx-git-support-for-gitla…
Browse files Browse the repository at this point in the history
…b-bitbucket-azure

[FEATURE]: git support for gitlab bitbucket azure
  • Loading branch information
hwixley authored May 23, 2024
2 parents 606d5e2 + e5a97d4 commit 6da5ea5
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 42 deletions.
16 changes: 8 additions & 8 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Optimize your development productivity in the terminal

<hr>

[![CODEQL](https://github.com/hwixley/wyx-cli/actions/workflows/github-code-scanning/codeql/badge.svg)](https://hwixley.github.io/wyx-cli/) [![Deploy Jekyll GH-Pages](https://github.com/hwixley/WYX-CLI/actions/workflows/jekyll-gh-pages.yml/badge.svg)](https://github.com/hwixley/WYX-CLI/actions/workflows/jekyll-gh-pages.yml) [![Generate Stdout Image](https://github.com/hwixley/WYX-CLI/actions/workflows/main.yml/badge.svg)](https://github.com/hwixley/WYX-CLI/actions/workflows/main.yml)<br>![License](https://img.shields.io/badge/License-MIT-purple?labelColor=gray&style=flat) ![Version](https://img.shields.io/badge/Version-3.1.2-blue?labelColor=gray&style=flat) ![Shell Support](https://img.shields.io/badge/Shell%20Support-BASH%20&%20ZSH-orange?labelColor=gray&style=flat) ![Operating Systems](https://img.shields.io/badge/OS%20Support-Debian%20Distros%20&%20MacOS-mediumpurple?labelColor=gray&style=flat)
[![CODEQL](https://github.com/hwixley/wyx-cli/actions/workflows/github-code-scanning/codeql/badge.svg)](https://hwixley.github.io/wyx-cli/) [![Deploy Jekyll GH-Pages](https://github.com/hwixley/WYX-CLI/actions/workflows/jekyll-gh-pages.yml/badge.svg)](https://github.com/hwixley/WYX-CLI/actions/workflows/jekyll-gh-pages.yml) [![Generate Stdout Image](https://github.com/hwixley/WYX-CLI/actions/workflows/main.yml/badge.svg)](https://github.com/hwixley/WYX-CLI/actions/workflows/main.yml)<br>![License](https://img.shields.io/badge/License-MIT-purple?labelColor=gray&style=flat) ![Version](https://img.shields.io/badge/Version-3.1.3-blue?labelColor=gray&style=flat) ![Shell Support](https://img.shields.io/badge/Shell%20Support-BASH%20&%20ZSH-orange?labelColor=gray&style=flat) ![Operating Systems](https://img.shields.io/badge/OS%20Support-Debian%20Distros%20&%20MacOS-mediumpurple?labelColor=gray&style=flat) ![Git Support](https://img.shields.io/badge/Git%20Support-GitHub,%20GitLab,%20BitBucket,%20&%20Azure%20DevOps-brown?labelColor=gray&style=flat)

<hr>
<p align="center">
Expand Down Expand Up @@ -139,16 +139,16 @@ wyx list-deps
- `commits`: View Your Branch Git Commits
- `lastcommit`: View Your Last Commit & Copy It's SHA
- `nb <branch-name?>`: Checkout-Add-Commit-Push A New Git Branch
- `pr`: Open A Pull Request From Your Current Git Branch on GitHub
- `bpr <branch-name?>`: Checkout-Add-Commit-Push A New Git Branch & Open A PR For It On GitHub
- `pr`: Open A Pull Request From Your Current Git Branch on GitHub/GitLab/BitBucket/Azure
- `bpr <branch-name?>`: Checkout-Add-Commit-Push New Git Branch & Open PR On GitHub/GitLab/BitBucket/Azure
- `pp`: Pull-Push Git Changes to Current Branch

### URLs:
- `repo`: View Your Repository On GitHub
- `branch`: View Your Current Branch On GitHub
- `actions`: View Your Repository Actions On GitHub
- `issues`: View Your Repository Issues On GitHub
- `prs`: View Your Repository PRs On GitHub
- `repo`: View Your Repository On GitHub/GitLab/BitBucket/Azure
- `branch`: View Your Current Branch On GitHub/GitLab/BitBucket/Azure
- `pipelines`: View Your Pipelines On GitHub/GitLab/BitBucket/Azure
- `issues`: View Your Repository Issues On GitHub/GitLab/BitBucket/Azure
- `prs`: View Your Repository PRs On GitHub/GitLab/BitBucket/Azure
- `notifs`: View Your GitHub Notifications
- `profile`: View Your GitHub Profile
- `org <myorg?>`: View Your GitHub Organisation
Expand Down
2 changes: 1 addition & 1 deletion .github/README_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Optimize your development productivity in the terminal

<hr>

[![CODEQL](https://github.com/hwixley/wyx-cli/actions/workflows/github-code-scanning/codeql/badge.svg)](https://hwixley.github.io/wyx-cli/) [![Deploy Jekyll GH-Pages](https://github.com/hwixley/WYX-CLI/actions/workflows/jekyll-gh-pages.yml/badge.svg)](https://github.com/hwixley/WYX-CLI/actions/workflows/jekyll-gh-pages.yml) [![Generate Stdout Image](https://github.com/hwixley/WYX-CLI/actions/workflows/main.yml/badge.svg)](https://github.com/hwixley/WYX-CLI/actions/workflows/main.yml)<br>![License](https://img.shields.io/badge/License-MIT-purple?labelColor=gray&style=flat) ![Version](https://img.shields.io/badge/Version-@VERSION@-blue?labelColor=gray&style=flat) ![Shell Support](https://img.shields.io/badge/Shell%20Support-BASH%20&%20ZSH-orange?labelColor=gray&style=flat) ![Operating Systems](https://img.shields.io/badge/OS%20Support-Debian%20Distros%20&%20MacOS-mediumpurple?labelColor=gray&style=flat)
[![CODEQL](https://github.com/hwixley/wyx-cli/actions/workflows/github-code-scanning/codeql/badge.svg)](https://hwixley.github.io/wyx-cli/) [![Deploy Jekyll GH-Pages](https://github.com/hwixley/WYX-CLI/actions/workflows/jekyll-gh-pages.yml/badge.svg)](https://github.com/hwixley/WYX-CLI/actions/workflows/jekyll-gh-pages.yml) [![Generate Stdout Image](https://github.com/hwixley/WYX-CLI/actions/workflows/main.yml/badge.svg)](https://github.com/hwixley/WYX-CLI/actions/workflows/main.yml)<br>![License](https://img.shields.io/badge/License-MIT-purple?labelColor=gray&style=flat) ![Version](https://img.shields.io/badge/Version-@VERSION@-blue?labelColor=gray&style=flat) ![Shell Support](https://img.shields.io/badge/Shell%20Support-BASH%20&%20ZSH-orange?labelColor=gray&style=flat) ![Operating Systems](https://img.shields.io/badge/OS%20Support-Debian%20Distros%20&%20MacOS-mediumpurple?labelColor=gray&style=flat) ![Git Support](https://img.shields.io/badge/Git%20Support-GitHub,%20GitLab,%20BitBucket,%20&%20Azure%20DevOps-brown?labelColor=gray&style=flat)

<hr>
<p align="center">
Expand Down
24 changes: 21 additions & 3 deletions argparse.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# CLI CONSTS
version="3.1.2"
version="3.1.3"
num_args=$#
date=$(date)
year="${date:24:29}"
Expand All @@ -21,9 +21,27 @@ branch=""
if git rev-parse --git-dir > /dev/null 2>&1; then
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
fi
remote=$(git config --get remote.origin.url | sed 's/.*\/\([^ ]*\/[^.]*\).*/\1/')
repo_url=${remote#"git@github.com:"}
remote=$(git config --get remote.origin.url)
repo_url=$(echo "$remote" | sed 's/[^ \/]*\/\([^ ]*\/[^.]*\).*/\1/')
repo_url=${repo_url%".git"}
git_host=""
if [[ $remote == *"github.com"* ]]; then
git_host="github"
repo_url=${repo_url#"git@github.com:"}
elif [[ $remote == *"gitlab.com"* ]]; then
git_host="gitlab"
repo_url=${repo_url#"git@gitlab.com:"}
elif [[ $remote == *"bitbucket.org"* ]]; then
git_host="bitbucket"
repo_url=$(echo "$repo_url" | sed 's/\/[^ \/]*\/\([^ \/]*\/[^ \/]*\)/\1/')
elif [[ $remote == *"azure.com"* ]]; then
git_host="azure"
org=$(echo "$repo_url" | sed 's/\([^ \/]*\).*/\1/')
project=$(echo "$repo_url" | sed 's/[^ \/]*\/\([^ \/]*\).*/\1/')
repo=$(echo "$repo_url" | sed 's/.*\/\([^ \/]*\)/\1/')
repo_url="${org}/${project}/_git/${repo}"
fi



if [ $num_args -eq 0 ]; then
Expand Down
101 changes: 99 additions & 2 deletions src/classes/wgit/wgit.class
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,105 @@ wgit.pull() {
git pull origin "$1"
}

wgit.pr() {
if wgit.is_git_repo ; then
if [[ "$git_host" == "github" ]]; then
sys.util.openurl "https://github.com/$repo_url/pull/new/$1"
elif [[ "$git_host" == "gitlab" ]]; then
sys.util.openurl "https://gitlab.com/$repo_url/-/merge_requests/new?merge_request%5Bsource_branch%5D=$1"
elif [[ "$git_host" == "bitbucket" ]]; then
sys.util.openurl "https://bitbucket.org/$repo_url/pull-requests/new?source=$1"
elif [[ "$git_host" == "azure" ]]; then
sys.util.openurl "https://dev.azure.com/$repo_url/pullrequestcreate?sourceRef=$1"
else
sys.log.error "This is not a supported git host..."
fi
fi
}

wgit.bpr() {
wgit.npush "$1"
sys.log.info "Creating PR for $branch in $repo_url..."
sys.util.openurl "https://github.com/$repo_url/pull/new/$1"
wgit.pr "$1"
}

wgit.repo_url() {
if wgit.is_git_repo ; then
if [[ "$git_host" = "github" ]]; then
wgit.giturl "https://github.com/$repo_url"
elif [[ "$git_host" = "gitlab" ]]; then
wgit.giturl "https://gitlab.com/$repo_url"
elif [[ "$git_host" = "bitbucket" ]]; then
wgit.giturl "https://bitbucket.org/$repo_url"
elif [[ "$git_host" = "azure" ]]; then
wgit.giturl "https://dev.azure.com/$repo_url"
else
sys.log.error "This is not a supported git host..."
fi
fi
}

wgit.prs_url() {
if wgit.is_git_repo ; then
if [[ "$git_host" = "github" ]]; then
wgit.giturl "https://github.com/$repo_url/pulls"
elif [[ "$git_host" = "gitlab" ]]; then
wgit.giturl "https://gitlab.com/$repo_url/merge_requests"
elif [[ "$git_host" = "bitbucket" ]]; then
wgit.giturl "https://bitbucket.org/$repo_url/pull-requests"
elif [[ "$git_host" = "azure" ]]; then
wgit.giturl "https://dev.azure.com/$repo_url/pullrequests"
else
sys.log.error "This is not a supported git host..."
fi
fi
}

wgit.branch_url() {
if wgit.is_git_repo ; then
if [[ "$git_host" = "github" ]]; then
wgit.giturl "https://github.com/$repo_url/tree/$branch"
elif [[ "$git_host" = "gitlab" ]]; then
wgit.giturl "https://gitlab.com/$repo_url/-/tree/$branch"
elif [[ "$git_host" = "bitbucket" ]]; then
wgit.giturl "https://bitbucket.org/$repo_url/branch/$branch"
elif [[ "$git_host" = "azure" ]]; then
wgit.giturl "https://dev.azure.com/$repo_url?path=%2F&version=GB$branch&_a=contents"
else
sys.log.error "This is not a supported git host..."
fi
fi
}

wgit.issues_url() {
if wgit.is_git_repo ; then
if [[ "$git_host" = "github" ]]; then
wgit.giturl "https://github.com/$repo_url/issues"
elif [[ "$git_host" = "gitlab" ]]; then
wgit.giturl "https://gitlab.com/$repo_url/issues"
elif [[ "$git_host" = "bitbucket" ]]; then
wgit.giturl "https://bitbucket.org/$repo_url/issues"
elif [[ "$git_host" = "azure" ]]; then
new_repo_url=$(echo "$repo_url" | sed 's|/_git/.*||')
wgit.giturl "https://dev.azure.com/${new_repo_url}/_workitems"
else
sys.log.error "This is not a supported git host..."
fi
fi
}

wgit.pipelines_url() {
if wgit.is_git_repo ; then
if [[ "$git_host" = "github" ]]; then
wgit.giturl "https://github.com/$repo_url/actions"
elif [[ "$git_host" = "gitlab" ]]; then
wgit.giturl "https://gitlab.com/$repo_url/pipelines"
elif [[ "$git_host" = "bitbucket" ]]; then
wgit.giturl "https://bitbucket.org/$repo_url/pipelines"
elif [[ "$git_host" = "azure" ]]; then
new_repo_url=$(echo "$repo_url" | sed 's|/_git/.*||')
wgit.giturl "https://dev.azure.com/$new_repo_url/_build"
else
sys.log.error "This is not a supported git host..."
fi
fi
}
2 changes: 1 addition & 1 deletion src/commands/branch.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

sys.log.info "Redirecting to $branch on $repo_url..."
wgit.giturl "https://github.com/$repo_url/tree/$branch"
wgit.branch_url
2 changes: 1 addition & 1 deletion src/commands/issues.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

sys.log.info "Redirecting to Issues on $repo_url..."
wgit.giturl "https://github.com/$repo_url/issues"
wgit.issues_url
2 changes: 1 addition & 1 deletion src/commands/actions.sh → src/commands/pipelines.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

sys.log.info "Redirecting to Action Workflows on $repo_url..."
wgit.giturl "https://github.com/$repo_url/actions"
wgit.pipelines_url
2 changes: 1 addition & 1 deletion src/commands/pr.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

sys.log.info "Creating PR for $branch in $repo_url..."
wgit.giturl "https://github.com/$repo_url/pull/new/$branch"
wgit.pr "$branch"
2 changes: 1 addition & 1 deletion src/commands/profile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash

sys.util.openurl "https://github.com/$(wyxd.user.username)"
wgit.giturl "https://github.com/$(wyxd.user.username)"
2 changes: 1 addition & 1 deletion src/commands/prs.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

sys.log.info "Redirecting to Pull Requests on $repo_url..."
wgit.giturl "https://github.com/$repo_url/pulls"
wgit.prs_url
2 changes: 1 addition & 1 deletion src/commands/repo.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

sys.log.info "Redirecting to $repo_url..."
wgit.giturl "https://github.com/$repo_url"
wgit.repo_url
14 changes: 7 additions & 7 deletions src/data/.cache/cmdinfo.git.wyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
- `commits`: View Your Branch Git Commits
- `lastcommit`: View Your Last Commit & Copy It's SHA
- `nb <branch-name?>`: Checkout-Add-Commit-Push A New Git Branch
- `pr`: Open A Pull Request From Your Current Git Branch on GitHub
- `bpr <branch-name?>`: Checkout-Add-Commit-Push A New Git Branch & Open A PR For It On GitHub
- `pr`: Open A Pull Request From Your Current Git Branch on GitHub/GitLab/BitBucket/Azure
- `bpr <branch-name?>`: Checkout-Add-Commit-Push New Git Branch & Open PR On GitHub/GitLab/BitBucket/Azure
- `pp`: Pull-Push Git Changes to Current Branch

### URLs:
- `repo`: View Your Repository On GitHub
- `branch`: View Your Current Branch On GitHub
- `actions`: View Your Repository Actions On GitHub
- `issues`: View Your Repository Issues On GitHub
- `prs`: View Your Repository PRs On GitHub
- `repo`: View Your Repository On GitHub/GitLab/BitBucket/Azure
- `branch`: View Your Current Branch On GitHub/GitLab/BitBucket/Azure
- `pipelines`: View Your Pipelines On GitHub/GitLab/BitBucket/Azure
- `issues`: View Your Repository Issues On GitHub/GitLab/BitBucket/Azure
- `prs`: View Your Repository PRs On GitHub/GitLab/BitBucket/Azure
- `notifs`: View Your GitHub Notifications
- `profile`: View Your GitHub Profile
- `org <myorg?>`: View Your GitHub Organisation
Expand Down
14 changes: 7 additions & 7 deletions src/data/.cache/cmdinfo.term.wyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
- commits: View Your Branch Git Commits
- lastcommit: View Your Last Commit & Copy It's SHA
- nb <branch-name?>: Checkout-Add-Commit-Push A New Git Branch
- pr: Open A Pull Request From Your Current Git Branch on GitHub
- bpr <branch-name?>: Checkout-Add-Commit-Push A New Git Branch & Open A PR For It On GitHub
- pr: Open A Pull Request From Your Current Git Branch on GitHub/GitLab/BitBucket/Azure
- bpr <branch-name?>: Checkout-Add-Commit-Push New Git Branch & Open PR On GitHub/GitLab/BitBucket/Azure
- pp: Pull-Push Git Changes to Current Branch

URLs:
- repo: View Your Repository On GitHub
- branch: View Your Current Branch On GitHub
- actions: View Your Repository Actions On GitHub
- issues: View Your Repository Issues On GitHub
- prs: View Your Repository PRs On GitHub
- repo: View Your Repository On GitHub/GitLab/BitBucket/Azure
- branch: View Your Current Branch On GitHub/GitLab/BitBucket/Azure
- pipelines: View Your Pipelines On GitHub/GitLab/BitBucket/Azure
- issues: View Your Repository Issues On GitHub/GitLab/BitBucket/Azure
- prs: View Your Repository PRs On GitHub/GitLab/BitBucket/Azure
- notifs: View Your GitHub Notifications
- profile: View Your GitHub Profile
- org <myorg?>: View Your GitHub Organisation
Expand Down
14 changes: 7 additions & 7 deletions src/data/arg_scripts.csv
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ ginit,ginit,"Initialise Git Repository",true,,git
push,push,"Add-Commit-Push Git Changes to Current Branch",true,,git
pull,pull,"Pull Git Changes for Current Branch",true,,git
mpull,mpull,"Checkout-Pull Git Changes From Master/Main Branch",true,,git
repo,repo,"View Your Repository On GitHub",true,,urls
branch,branch,"View Your Current Branch On GitHub",true,,urls
actions,actions,"View Your Repository Actions On GitHub",true,,urls
issues,issues,"View Your Repository Issues On GitHub",true,,urls
prs,prs,"View Your Repository PRs On GitHub",true,,urls
repo,repo,"View Your Repository On GitHub/GitLab/BitBucket/Azure",true,,urls
branch,branch,"View Your Current Branch On GitHub/GitLab/BitBucket/Azure",true,,urls
pipelines,pipelines,"View Your Pipelines On GitHub/GitLab/BitBucket/Azure",true,,urls
issues,issues,"View Your Repository Issues On GitHub/GitLab/BitBucket/Azure",true,,urls
prs,prs,"View Your Repository PRs On GitHub/GitLab/BitBucket/Azure",true,,urls
notifs,notifs,"View Your GitHub Notifications",true,,urls
commits,commits,"View Your Branch Git Commits",true,,git
lastcommit,lastcommit,"View Your Last Commit & Copy It's SHA",true,,git
nb,nb,"Checkout-Add-Commit-Push A New Git Branch",true,"<branch-name?>",git
pr,pr,"Open A Pull Request From Your Current Git Branch on GitHub",true,,git
bpr,bpr,"Checkout-Add-Commit-Push A New Git Branch & Open A PR For It On GitHub",true,"<branch-name?>",git
pr,pr,"Open A Pull Request From Your Current Git Branch on GitHub/GitLab/BitBucket/Azure",true,,git
bpr,bpr,"Checkout-Add-Commit-Push New Git Branch & Open PR On GitHub/GitLab/BitBucket/Azure",true,"<branch-name?>",git
profile,profile,"View Your GitHub Profile",true,,urls
org,org,"View Your GitHub Organisation",true,<myorg?>,urls
help,help,"View WYX-CLI Documentation",true,,hutil
Expand Down

0 comments on commit 6da5ea5

Please sign in to comment.