From a641012f842aba03ff7bcf3ed703c9ffd7b7ed96 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Wed, 26 Dec 2018 16:55:30 -0700 Subject: [PATCH 1/5] Add git-gitlab-mr Noel posted a link to this in the Hangops slack. --- README.md | 1 + bin/git-gitlab-mr | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100755 bin/git-gitlab-mr diff --git a/README.md b/README.md index 9d8460409..33d0f2b79 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ If you aren't using any ZSH frameworks, or if you're a `bash` user, do the follo | `git-forest` | Jan Engelhardt | Prints a text-based tree visualisation of your repository. Requires [Git.pm](https://metacpan.org/release/Git) | | `git-git` | Joe Block | Typing `git git foo` will make git do a `git foo` instead of complaining. | | `git-github-open` | ? | Open GitHub file/blob page for FILE on LINE. | +| `git-gitlab-mr` | Noel Cower's [gist](https://gist.github.com/nilium/ac808ee3729cdce01ec0f3c0a499f099) | Open a merge request on GitLab | | `git-ignored` | ? | Show files being ignored by git in the repo. | | `git-improved-merge` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | Sophisticated git merge with integrated CI check and automatic cleanup. | | `git-incoming-commits` | Ryan Tomayko's [dotfiles](https://github.com/rtomayko/dotfiles) | Adds a remote for the current repository for the given github username. | diff --git a/bin/git-gitlab-mr b/bin/git-gitlab-mr new file mode 100755 index 000000000..47bdc7ff6 --- /dev/null +++ b/bin/git-gitlab-mr @@ -0,0 +1,98 @@ +#!/usr/bin/env bash +# Copyright 2018 Noel Cower +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# git-mr: Simple script to open the URL for a new merge request for a GitLab +# repository. +# +# Note: Has no way of knowing something isn't a GitLab repository. + +set -e + +havecmd() { + [ -n "$(command -v "$@" 2>/dev/null)" ] +} + +err() { + echo "ERR $*" 1>&2 + exit 1 +} + +uriencode() { + jq -Rrns --arg in "$*" \ + '$in|split("\n")|if last == "" then .[:-1] else . end|join(" ")|@uri' +} + +if ! havecmd jq; then + err 'Required program missing: jq' +fi + +ref="$(git rev-parse --abbrev-ref --symbolic-full-name @{u})" +if [ -z "$ref" ]; then + err "No upstream for branch: $(git rev-parse --abbrev-ref --symbolic-full-name @)" +fi +repo="${ref%%/*}" +if [ -z "$repo" ]; then + err "Unable to determine repository for ref: $ref" +fi +branch="${ref#$repo/}" +if [ -z "$branch" ]; then + err "Unable to determine ref in repository of ref: $ref" +fi +uri="$(git remote get-url "$repo")" +if [ -z "$uri" ]; then + err "Unable to determine URI of repository: $repo" +fi + +scheme=https +suffix="/merge_requests/new?$(uriencode 'merge_request[source_branch]')=$(uriencode "${branch}")" +case "$uri" in +*@*:*) # SSH + uri="${uri#*@}" + domain="${uri%:*}" + path="/${uri#${domain}:}" + ;; +https://*) # HTTPS + uri="${uri#https://}" + uri="${uri#*@}" + domain="${uri%%/*}" + path="${uri#${domain}}" + ;; +http://*) # HTTP? + scheme=http # Why? Why do this? + uri="${uri#https://}" + uri="${uri#*@}" + domain="${uri%%/*}" + path="${uri#${domain}}" + ;; +*) + err "Unrecognized URI: $uri" + ;; +esac + +: "${mrurl=${scheme}://${domain}${path%.git}${suffix}}" +if havecmd open; then + open "$mrurl" +elif havecmd xdg-open; then + xdg-open "$mrurl" >/dev/null 2>&1 +else + # Print URL if we can't open it + echo "$mrurl" +fi From fc03f336400fb5df5e9b2cf14ec61a827dbb0303 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Wed, 26 Dec 2018 16:57:32 -0700 Subject: [PATCH 2/5] Tweak license notice --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 33d0f2b79..dd29dedb1 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,6 @@ [![Issue Count](https://codeclimate.com/github/unixorn/git-extra-commands/badges/issue_count.svg)](https://codeclimate.com/github/unixorn/git-extra-commands) [![GitHub stars](https://img.shields.io/github/stars/unixorn/git-extra-commands.svg)](https://github.com/unixorn/git-extra-commands/stargazers) -**git-extra-commands** is a ZSH plugin that packages some extra git helper scripts I've found. This collection (and the scripts that I wrote in it) is licensed with the Apache Version 2 license. - -Some of the scripts in this collection came from other sources and may have different licensing - if they do, their license information is included inline in the script source. - -This collection doesn't actually require ZSH, but packaging it as a ZSH plugin makes it more convenient for people using a ZSH framework to use this collection. - -If you wrote one of these scripts and want it removed from this collection, please either make a PR and/or file an issue against the repo and I will remove it. - **Table of Contents** @@ -36,6 +28,14 @@ If you wrote one of these scripts and want it removed from this collection, plea +**git-extra-commands** is a ZSH plugin that packages some extra `git` helper scripts I've found. This collection (and the scripts that I wrote in it) is licensed with the Apache Version 2 license. + +However, some of the scripts in this collection came from other sources and may have different licensing - if they do, their license information is included inline in the script source. + +This collection doesn't actually require ZSH, but packaging it as a ZSH plugin makes it more convenient for people using a ZSH framework to use this collection. + +If you wrote one of these scripts and want it removed from this collection, please either make a PR and/or file an issue against the repo and I will remove it. + ## Installing ### Pre-requisites From a8df894ba84ddc84c144c54d44c197945365fcc6 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Wed, 26 Dec 2018 16:58:33 -0700 Subject: [PATCH 3/5] Update TOC --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index dd29dedb1..2c24d041f 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ -**Table of Contents** +## Table of Contents - [Installing](#installing) - [Pre-requisites](#pre-requisites) From e4c7df95621a8fddd93ea727e09295f70275d701 Mon Sep 17 00:00:00 2001 From: Joe Block Date: Wed, 26 Dec 2018 17:49:58 -0700 Subject: [PATCH 4/5] Linter fixers --- bin/git-gitlab-mr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/git-gitlab-mr b/bin/git-gitlab-mr index 47bdc7ff6..ace182259 100755 --- a/bin/git-gitlab-mr +++ b/bin/git-gitlab-mr @@ -87,7 +87,7 @@ http://*) # HTTP? ;; esac -: "${mrurl=${scheme}://${domain}${path%.git}${suffix}}" +: "${mrurl:=${scheme}://${domain}${path%.git}${suffix}}" if havecmd open; then open "$mrurl" elif havecmd xdg-open; then @@ -95,4 +95,4 @@ elif havecmd xdg-open; then else # Print URL if we can't open it echo "$mrurl" -fi +fi \ No newline at end of file From bc222e28c95d096d6abc33cef325c4163c6eba9c Mon Sep 17 00:00:00 2001 From: Joe Block Date: Wed, 26 Dec 2018 17:54:01 -0700 Subject: [PATCH 5/5] Add git-wordiness --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2c24d041f..419292ff1 100644 --- a/README.md +++ b/README.md @@ -171,6 +171,7 @@ If you aren't using any ZSH frameworks, or if you're a `bash` user, do the follo | `git-where` | Mislav Marohnić's [dotfiles](https://github.com/mislav/dotfiles) | Shows where a particular commit falls between releases. | | `git-whoami` | Peter Eisentraut | Shows what username & email you have configured for the repo you're in | | `git-winner` | Garry Dolley [https://github.com/up_the_irons/git-winner](https://github.com/up_the_irons/git-winner) | Shows what authors have made the most commits, both by number of commits and by number of lines changed. | +| `git-wordiness` | Noel Cower | Shows how wordy people's commit messages are. Useful for shaming the folks who commit atrocities like `git commit -m fixup` | | `git-wtf` | William Morgan | `git-wtf` displays the state of your repository in a readable, easy-to-scan format. It's useful for getting a summary of how a branch relates to a remote server, and for wrangling many topic branches. | | `github-open` | Ryan Tomayko's [dotfiles](http://github.com/rtomayko/dotfiles) | |