Skip to content

Commit

Permalink
Introduce sub-command (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Jul 17, 2019
1 parent 3496b0a commit 32159f9
Show file tree
Hide file tree
Showing 6 changed files with 747 additions and 664 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.11.2
- image: circleci/golang:1.12
steps:
- run: |
mkdir -p ~/bin
Expand Down
115 changes: 67 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,19 @@ brew install ghcp

You need to get a personal access token from the [settings](https://github.com/settings/tokens) and set it to the `GITHUB_TOKEN` environment variable or `--token` option.

Let's see the following use cases.
Let's see the following examples.


### Release assets to GitHub Pages
### Example: Release assets to GitHub Pages

You can commit files to the `gh-pages` branch as follows:
To commit the files to the `gh-pages` branch:

```sh
ghcp -u YOUR -r REPO -b gh-pages -m MESSAGE index.html index.css
ghcp commit -u OWNER -r REPO -b gh-pages -m MESSAGE index.html index.css
```

You can commit files without parents by `--no-parent` option.
This is useful if you do not need past commits history.

```sh
ghcp -u YOUR -r REPO -b gh-pages --no-parent -m MESSAGE index.html index.css
```

### Release your Homebrew formula
### Example: Release your Homebrew formula

You can release a Homebrew formula to a tap repository.

Expand All @@ -49,8 +43,8 @@ Then create a formula file like:
# hello.rb
class Hello < Formula
desc "Your awesome application"
homepage "https://github.com/YOUR/hello"
url "https://github.com/YOUR/hello/releases/download/v1.0.0/hello_darwin_amd64"
homepage "https://github.com/OWNER/hello"
url "https://github.com/OWNER/hello/releases/download/v1.0.0/hello_darwin_amd64"
version "v1.0.0"
sha256 "SHA256_SUM"

Expand All @@ -64,23 +58,23 @@ class Hello < Formula
end
```

Commit the formula to the repository.
To commit the formula to the repository:

```sh
ghcp -u YOUR -r homebrew-hello -m v1.0.0 hello.rb
ghcp commit -u OWNER -r homebrew-hello -m v1.0.0 hello.rb
```

Now you can install the formula from the repository.

```sh
brew tap YOUR/hello
brew tap OWNER/hello
brew install hello
```

See also [Makefile](Makefile).
ghcp is released to [the tap repository](https://github.com/int128/homebrew-ghcp) by using ghcp.

### Bump version string
### Example: Bump version string

You can change version string in files such as README or build script.
For example,
Expand All @@ -90,63 +84,88 @@ For example,
sed -i -e "s/version '[0-9.]*'/version '$TAG'/g" README.md build.gradle

# commit the changes to a new branch
ghcp -u YOUR -r REPO -B bump-v1.1.0 -m v1.1.0 README.md build.gradle
ghcp commit-new-branch -u OWNER -r REPO -b bump-v1.1.0 -m v1.1.0 README.md build.gradle
```


## Usage

```
Usage: ghcp [options] [file or directory...]
Options:
--api string GitHub API v3 URL (v4 will be inferred) [$GITHUB_API]
-b, --branch string Update the branch (default: default branch of repository)
--debug Show debug logs
-C, --directory string Change to directory before copy
--dry-run Upload files but do not update the branch actually
-m, --message string Commit message (mandatory)
-B, --new-branch string Create a branch
--no-file-mode Ignore executable bit of file and treat as 0644
--no-parent Create a commit without a parent
-u, --owner string GitHub repository owner (mandatory)
--parent string Create a commit from the parent branch or tag (default: default branch of repository)
-r, --repo string GitHub repository name (mandatory)
--token string GitHub API token [$GITHUB_TOKEN]
Usage:
ghcp [command]
Available Commands:
commit Commit files to the existing branch
commit-new-branch Commit files to a new branch
help Help about any command
Flags:
--api string GitHub API v3 URL (v4 will be inferred) [$GITHUB_API]
--debug Show debug logs
-C, --directory string Change to directory before operation
-h, --help help for main
--token string GitHub API token [$GITHUB_TOKEN]
```

Author and comitter of a commit are set to the login user, that depends on the token.
ghcp does not create a new commit if the branch has same files, that prevents an empty commit.
ghcp does not read the current Git config and Git state and you need to always set owner and name of a repository.

### Examples
```
Usage:
ghcp commit [flags]
Flags:
-b, --branch string Name of the branch to update (default: the default branch)
--dry-run Upload files but do not update the branch actually
-h, --help help for commit
-m, --message string Commit message (mandatory)
--no-file-mode Ignore executable bit of file and treat as 0644
-u, --owner string GitHub repository owner (mandatory)
-r, --repo string GitHub repository name (mandatory)
```

The following examples show how to commit files to the repository `https://github.com/YOUR/REPO.git`.
```
Usage:
ghcp commit-new-branch [flags]
Flags:
-b, --branch string Name of a branch to create (mandatory)
--dry-run Upload files but do not update the branch actually
-h, --help help for commit-new-branch
-m, --message string Commit message (mandatory)
--no-file-mode Ignore executable bit of file and treat as 0644
--no-parent Create a commit without a parent
-u, --owner string GitHub repository owner (mandatory)
--parent string Create a commit from the parent branch or tag (default: the default branch)
-r, --repo string GitHub repository name (mandatory)
```

To commit files and update the default branch:
To commit the files to the default branch:

```sh
ghcp -u YOUR -r REPO -m MESSAGE FILES...
ghcp commit -u OWNER -r REPO -m MESSAGE FILES...
```

To commit files and update the branch `gh-pages`:
To commit the files to the branch:

```sh
ghcp -u YOUR -r REPO -b gh-pages -m MESSAGE FILES...
ghcp commit -u OWNER -r REPO -b BRANCH -m MESSAGE FILES...
```

To commit files and create a new branch `topic` based on the default branch:
To commit the files to a new branch from the default branch:

```sh
ghcp -u YOUR -r REPO -B topic -m MESSAGE FILES...
ghcp commit-new-branch -u OWNER -r REPO -b BRANCH -m MESSAGE FILES...
```

To commit files and create a new branch `topic` based on the branch `develop`:
To commit the files to a new branch from the parent branch:

```sh
ghcp -u YOUR -r REPO -B topic --parent develop -m MESSAGE FILES...
ghcp commit-new-branch -u OWNER -r REPO -b BRANCH --parent PARENT -m MESSAGE FILES...
```

Author and comitter of a commit are set to the login user, that depends on the token.
ghcp does not create a new commit if the branch has same files, that prevents an empty commit.
ghcp does not read the current Git config and Git state and you need to always set owner and name of a repository.


### Working with CI

Here is an example for CircleCI:
Expand Down
Loading

0 comments on commit 32159f9

Please sign in to comment.