Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into pr-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Aug 2, 2020
2 parents 5c6dbb4 + 705360d commit 393e75a
Show file tree
Hide file tree
Showing 556 changed files with 1,529 additions and 301,940 deletions.
74 changes: 34 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,39 @@ jobs:
strategy:
fail-fast: false
matrix:
go: [ '1.9', '1.10', '1.11', '1.12', '1.13' ]
go: ["1.11", "1.12", "1.13", "1.14"]

steps:
- uses: actions/checkout@v1

- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x

- name: Cache gems
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gem-
- name: Bundle install
run: |
bundle install --path vendor/bundle
bundle binstub cucumber --path bin
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}

# - name: Install system packages
# if: runner.os == 'Linux'
# run: sudo apt-get install -y zsh fish

- name: Run tests
shell: bash
run: |
export GOPATH="$HOME"/go
mkdir -p "$GOPATH"/src/github.com/github
ln -svf "$PWD" "$GOPATH"/src/github.com/github/hub
cd "$GOPATH"/src/github.com/github/hub
make test-all
env:
CI: true
- uses: actions/checkout@v1

- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x

- name: Cache gems
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gem-
- name: Bundle install
run: |
bundle install --path vendor/bundle
bundle binstub cucumber --path bin
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}

# - name: Install system packages
# if: runner.os == 'Linux'
# run: sudo apt-get install -y zsh fish

- name: Run tests
run: make test-all
env:
CI: true
31 changes: 15 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
name: Release
on:
push:
tags: 'v*'
tags: "v*"

jobs:
release:
name: Publish release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: "1.13"
- name: Run tests
run: script/publish-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
homebrew:
name: Bump Homebrew formula
runs-on: ubuntu-latest
steps:
- uses: mislav/[email protected]
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: "1.13"

- name: Publish release script
run: script/publish-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: mislav/bump-homebrew-formula-action@v1
if: "!contains(github.ref, '-')" # skip prereleases
with:
formula-name: hub
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ tags
/site
/hub
.vscode
.DS_Store
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get purge --auto-remove -y curl \
&& rm -rf /var/lib/apt/lists/*

RUN groupadd -r app && useradd -r -g app -G sudo app \
&& mkdir -p /home/app && chown -R app:app /home/app
&& mkdir -p /home/app && chown -R app:app /home/app
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

USER app
Expand All @@ -20,5 +20,4 @@ COPY Gemfile Gemfile.lock ./
RUN bundle install

ENV LANG C.UTF-8
ENV GOFLAGS -mod=vendor
ENV USER app
22 changes: 10 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
SOURCES = $(shell script/build files)
SOURCES = $(shell go list -f '{{range .GoFiles}}{{$$.Dir}}/{{.}}\
{{end}}' ./...)
SOURCE_DATE_EPOCH ?= $(shell date +%s)
BUILD_DATE = $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" '+%d %b %Y' 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" '+%d %b %Y')
HUB_VERSION = $(shell bin/hub version | tail -1)
FLAGS_ALL = $(shell go version | grep -q 'go1.[89]' || echo 'all=')
export GOFLAGS := $(shell go version | grep -q 'go1.1[^0]' && echo '-mod=vendor')
export LDFLAGS := -extldflags '$(LDFLAGS)'
export GCFLAGS := $(FLAGS_ALL)-trimpath '$(PWD)'
export ASMFLAGS := $(FLAGS_ALL)-trimpath '$(PWD)'

ifneq ($(GOFLAGS),)
export GO111MODULE=on
unexport GOPATH
endif
export GO111MODULE=on
unexport GOPATH

export LDFLAGS := -extldflags '$(LDFLAGS)'
export GCFLAGS := all=-trimpath '$(PWD)'
export ASMFLAGS := all=-trimpath '$(PWD)'

MIN_COVERAGE = 89.4
MIN_COVERAGE = 90.2

HELP_CMD = \
share/man/man1/hub-alias.1 \
Expand Down Expand Up @@ -53,7 +51,7 @@ bin/hub: $(SOURCES)
script/build -o $@

bin/md2roff: $(SOURCES)
go build -o $@ github.com/github/hub/md2roff-bin
go build -o $@ github.com/github/hub/v2/md2roff-bin

test:
go test ./...
Expand Down
83 changes: 57 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
hub is a command line tool that wraps `git` in order to extend it with extra
features and commands that make working with GitHub easier.

For an official, potentially more user-friendly command-line interface to GitHub,
see [cli.github.com](https://cli.github.com) and
[this comparison](https://github.com/cli/cli/blob/trunk/docs/gh-vs-hub.md).

This repository and its issue tracker is **not for reporting problems with
GitHub.com** web interface. If you have a problem with GitHub itself, please
[contact Support](https://github.com/contact).
Expand All @@ -10,19 +14,23 @@ Usage

``` sh
$ hub clone rtomayko/tilt

# expands to:
#=> git clone git://github.com/rtomayko/tilt.git

# if you prefer HTTPS to git/SSH protocols:
$ git config --global hub.protocol https
$ hub clone rtomayko/tilt
#=> git clone https://github.com/rtomayko/tilt.git
```

hub can be safely [aliased](#aliasing) as `git` so you can type `$ git
<command>` in the shell and get all the usual `hub` features.
See [usage examples](https://hub.github.com/#developer) or the [full reference
documentation](https://hub.github.com/hub.1.html) to see all available commands
and flags.

See [Usage documentation](https://hub.github.com/hub.1.html) for the list of all
commands and their arguments.
hub can also be used to make shell scripts that [directly interact with the
GitHub API](https://hub.github.com/#scripting).

hub can also be used to make shell scripts that [manually interface with the
GitHub API](https://hub.github.com/hub-api.1.html).
hub can be safely [aliased](#aliasing) as `git`, so you can type `$ git
<command>` in the shell and have it expanded with `hub` features.

Installation
------------
Expand All @@ -39,20 +47,51 @@ Fedora Linux | [DNF](https://fedoraproject.org/wiki/DNF) | `sudo dnf install hub
Arch Linux | [pacman](https://wiki.archlinux.org/index.php/pacman) | `sudo pacman -S hub`
FreeBSD | [pkg(8)](http://man.freebsd.org/pkg/8) | `pkg install hub`
Debian | [apt(8)](https://manpages.debian.org/buster/apt/apt.8.en.html) | `sudo apt install hub`
Ubuntu | [Snap](https://snapcraft.io) | `snap install hub --classic`
Ubuntu | [Snap](https://snapcraft.io) | [We do not recommend installing the snap anymore.](https://github.com/github/hub/issues?q=is%3Aissue+snap)
openSUSE | [Zypper](https://en.opensuse.org/SDB:Zypper_manual) | `sudo zypper install hub`
Void Linux | [xbps](https://github.com/void-linux/xbps) | `sudo xbps-install -S hub`
Gentoo | [Portage](https://wiki.gentoo.org/wiki/Portage) | `sudo emerge dev-vcs/hub`
_any_ | [conda](https://docs.conda.io/en/latest/) | `conda install -c conda-forge hub`


Packages other than Homebrew are community-maintained (thank you!) and they
are not guaranteed to match the [latest hub release][latest]. Check `hub
version` after installing a community package.

#### Standalone

`hub` can be easily installed as an executable. Download the latest
[compiled binaries](https://github.com/github/hub/releases) and put it anywhere
in your executable path.
`hub` can be easily installed as an executable. Download the [latest
binary][latest] for your system and put it anywhere in your executable path.

#### GitHub Actions

hub is ready to be used in your [GitHub Actions][] workflows:
```yaml
steps:
- uses: actions/checkout@v2

- name: List open pull requests
run: hub pr list
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Note that the default `secrets.GITHUB_TOKEN` will only work for API operations
scoped to the repository that runs this workflow. If you need to interact with other
repositories, [generate a Personal Access Token][pat] with at least the `repo` scope
and add it to your [repository secrets][].


[github actions]: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
[pat]: https://github.com/settings/tokens
[repository secrets]: https://docs.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets

#### Source

Prerequisites for building from source are:

* `make`
* [Go 1.9+](https://golang.org/doc/install)
* [Go 1.11+](https://golang.org/doc/install)

Clone this repository and run `make install`:

Expand All @@ -67,11 +106,6 @@ cd hub
make install prefix=/usr/local
```

This assumes support for [Go 1.11+
modules](https://github.com/golang/go/wiki/Modules). If you are building on an
older version of Go, you will need to clone the repository into
`$GOPATH/src/github.com/github/hub`.

Aliasing
--------

Expand Down Expand Up @@ -113,18 +147,15 @@ New-Item -Type file -Force $PROFILE

### Shell tab-completion

hub repository contains tab-completion scripts for bash, zsh and fish.
hub repository contains [tab-completion scripts](./etc) for bash, zsh and fish.
These scripts complement existing completion scripts that ship with git.

[Installation instructions](etc)
* [hub bash completion](https://github.com/github/hub/blob/master/etc/hub.bash_completion.sh)
* [hub zsh completion](https://github.com/github/hub/blob/master/etc/hub.zsh_completion)
* [hub fish completion](https://github.com/github/hub/blob/master/etc/hub.fish_completion)
Meta
----

* Home: <https://github.com/github/hub>
* Bugs: <https://github.com/github/hub/issues>
* Authors: <https://github.com/github/hub/contributors>
* Our [Code of Conduct](https://github.com/github/hub/blob/master/CODE_OF_CONDUCT.md)


[latest]: https://github.com/github/hub/releases/latest
21 changes: 16 additions & 5 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"strings"
"syscall"

"github.com/github/hub/ui"
"github.com/github/hub/v2/ui"
)

// Cmd is a project-wide struct that represents a command to be run in the console.
type Cmd struct {
Name string
Args []string
Expand All @@ -20,9 +21,20 @@ type Cmd struct {
}

func (cmd Cmd) String() string {
return fmt.Sprintf("%s %s", cmd.Name, strings.Join(cmd.Args, " "))
args := make([]string, len(cmd.Args))
for i, a := range cmd.Args {
if strings.ContainsRune(a, '"') {
args[i] = fmt.Sprintf(`'%s'`, a)
} else if a == "" || strings.ContainsRune(a, '\'') || strings.ContainsRune(a, ' ') {
args[i] = fmt.Sprintf(`"%s"`, a)
} else {
args[i] = a
}
}
return fmt.Sprintf("%s %s", cmd.Name, strings.Join(args, " "))
}

// WithArg returns the current argument
func (cmd *Cmd) WithArg(arg string) *Cmd {
cmd.Args = append(cmd.Args, arg)

Expand Down Expand Up @@ -64,9 +76,8 @@ func (cmd *Cmd) Success() bool {
func (cmd *Cmd) Run() error {
if isWindows() {
return cmd.Spawn()
} else {
return cmd.Exec()
}
return cmd.Exec()
}

func isWindows() bool {
Expand Down Expand Up @@ -137,7 +148,7 @@ func NewWithArray(cmd []string) *Cmd {

func verboseLog(cmd *Cmd) {
if os.Getenv("HUB_VERBOSE") != "" {
msg := fmt.Sprintf("$ %s %s", cmd.Name, strings.Join(cmd.Args, " "))
msg := fmt.Sprintf("$ %s", cmd.String())
if ui.IsTerminal(os.Stderr) {
msg = fmt.Sprintf("\033[35m%s\033[0m", msg)
}
Expand Down
10 changes: 9 additions & 1 deletion cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"testing"

"github.com/bmizerany/assert"
"github.com/github/hub/v2/internal/assert"
)

func TestNew(t *testing.T) {
Expand All @@ -18,3 +18,11 @@ func TestWithArg(t *testing.T) {
assert.Equal(t, "git", execCmd.Name)
assert.Equal(t, 4, len(execCmd.Args))
}

func Test_String(t *testing.T) {
c := Cmd{
Name: "echo",
Args: []string{"hi", "hello world", "don't", `"fake news"`},
}
assert.Equal(t, `echo hi "hello world" "don't" '"fake news"'`, c.String())
}
Loading

0 comments on commit 393e75a

Please sign in to comment.