Skip to content

Commit b41d029

Browse files
grevychgerardo-reyes-s1
authored andcommitted
feat: brnchswppr initial version
1 parent 6ffdee9 commit b41d029

19 files changed

+3006
-1
lines changed

.circleci/config.yml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
version: 2.1
2+
orbs:
3+
go: circleci/[email protected]
4+
commitlint: conventional-changelog/[email protected]
5+
6+
parameters:
7+
rebuild_cache:
8+
type: boolean
9+
default: false
10+
11+
# Extra contexts to expose to all jobs below
12+
contexts: &contexts
13+
- aws-credentials
14+
- ghaccesstoken
15+
- docker-registry
16+
- npm-credentials
17+
- vault-dev
18+
- confluence
19+
- circleci-credentials
20+
- tray-webhooks
21+
22+
# Configuration to pass to test and cache jobs
23+
cfg: &cfg
24+
context: *contexts
25+
26+
# Branches used for releasing code, pre-release or not
27+
release_branches: &release_branches
28+
- "main"
29+
30+
executors:
31+
commitlint-executor:
32+
docker:
33+
- image: cimg/node:current
34+
working_directory: ~/project
35+
36+
jobs:
37+
test:
38+
executor:
39+
name: go/default # Use the default executor from the orb
40+
tag: "1.22.2" # Specify a version tag
41+
steps:
42+
- checkout # checkout source code
43+
- go/load-cache # Load cached Go modules.
44+
- go/mod-download # Run 'go mod download'.
45+
- go/save-cache # Save Go modules to cache.
46+
- run:
47+
name: Run unit tests
48+
command: make test
49+
- run:
50+
name: Run integration tests
51+
command: make integration-test
52+
check-releaser:
53+
docker:
54+
- image: cimg/go:1.20
55+
steps:
56+
- checkout
57+
- run: curl -sfL https://goreleaser.com/static/run | bash -s -- check
58+
dry-release:
59+
docker:
60+
- image: cimg/go:1.20
61+
steps:
62+
- checkout
63+
- run: curl -sfL https://goreleaser.com/static/run | bash -s -- release --snapshot --clean
64+
release:
65+
docker:
66+
- image: cimg/go:1.20
67+
steps:
68+
- run: curl -sL https://git.io/autotag-install | sudo sh -s -- -b /usr/bin
69+
- checkout
70+
- run: autotag --scheme=conventional
71+
- run: curl -sfL https://goreleaser.com/static/run | bash
72+
setup-commitlint:
73+
executor: commitlint-executor
74+
steps:
75+
- checkout
76+
- restore_cache:
77+
key: lock-{{ checksum "package-lock.json" }}
78+
- run:
79+
name: Install dependencies
80+
command: npm install
81+
- save_cache:
82+
key: lock-{{ checksum "package-lock.json" }}
83+
paths:
84+
- node_modules
85+
- persist_to_workspace:
86+
root: ~/project
87+
paths:
88+
- node_modules
89+
lint-commit:
90+
executor: commitlint-executor
91+
steps:
92+
- checkout
93+
- attach_workspace:
94+
at: ~/project
95+
- run:
96+
name: Define environment variable with latest commit's message
97+
command: |
98+
echo 'export COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s")' >> $BASH_ENV
99+
source $BASH_ENV
100+
- run:
101+
name: Lint commit message
102+
command: echo "$COMMIT_MESSAGE" | npx commitlint
103+
check-initial-tag:
104+
docker:
105+
- image: cimg/base:stable
106+
steps:
107+
- checkout
108+
- run:
109+
name: Check initial tag v0.0.0
110+
command: make check-initial-tag
111+
112+
113+
workflows:
114+
released-version:
115+
jobs:
116+
- test:
117+
# Only run this job on git tag pushes
118+
filters:
119+
branches:
120+
ignore: /.*/
121+
tags:
122+
only: /v[0-9]+(\.[0-9]+)*(-.*)*/
123+
main:
124+
jobs:
125+
- setup-commitlint:
126+
filters:
127+
branches:
128+
only: main
129+
- lint-commit:
130+
requires:
131+
- setup-commitlint
132+
# Only run this job on git tag pushes
133+
filters:
134+
branches:
135+
only: main
136+
- test:
137+
# Only run this job on git tag pushes
138+
filters:
139+
branches:
140+
only: main
141+
- check-initial-tag:
142+
# Only run this job on git tag pushes
143+
filters:
144+
branches:
145+
only: main
146+
- dry-release:
147+
# Only run this job on git tag pushes
148+
filters:
149+
branches:
150+
only: main
151+
- release:
152+
# Only run this job on git tag pushes
153+
requires:
154+
- lint-commit
155+
- test
156+
- check-initial-tag
157+
- dry-release
158+
filters:
159+
branches:
160+
only: main
161+
162+
branch:
163+
jobs:
164+
- setup-commitlint
165+
- lint-commit:
166+
requires:
167+
- setup-commitlint
168+
- test:
169+
filters:
170+
branches:
171+
ignore: main
172+
tags:
173+
ignore: /.*/
174+
- check-releaser

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,25 @@
1717
# Dependency directories (remove the comment below to include it)
1818
# vendor/
1919

20+
# node
21+
node_modules/
22+
2023
# Go workspace file
2124
go.work
2225
go.work.sum
2326

2427
# env file
2528
.env
29+
30+
# binaries
31+
bin/
32+
dist/
33+
34+
# dev-tools
35+
.tool-versions
36+
37+
# debug
38+
.branchswap
39+
40+
# test output
41+
.branchswappr-*.test

.goreleaser.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
4+
# The lines below are called `modelines`. See `:help modeline`
5+
# Feel free to remove those if you don't want/need to use them.
6+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
7+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
8+
9+
version: 2
10+
11+
before:
12+
hooks:
13+
# You may remove this if you don't use go modules.
14+
- go mod tidy
15+
# you may remove this if you don't need go generate
16+
- go generate ./...
17+
18+
builds:
19+
- main: ./cmd/branchswapper.go
20+
binary: brnchswppr
21+
env:
22+
- CGO_ENABLED=0
23+
goos:
24+
- linux
25+
- windows
26+
- darwin
27+
28+
archives:
29+
- format: tar.gz
30+
# this name template makes the OS and Arch compatible with the results of `uname`.
31+
name_template: >-
32+
{{ .ProjectName }}_
33+
{{- title .Os }}_
34+
{{- if eq .Arch "amd64" }}x86_64
35+
{{- else if eq .Arch "386" }}i386
36+
{{- else }}{{ .Arch }}{{ end }}
37+
{{- if .Arm }}v{{ .Arm }}{{ end }}
38+
# use zip for windows archives
39+
format_overrides:
40+
- goos: windows
41+
format: zip
42+
43+
changelog:
44+
sort: asc
45+
filters:
46+
exclude:
47+
- "^docs:"
48+
- "^test:"

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
PATH := $(PATH):$(PWD)/bin
2+
3+
4+
.PHONY: build test integration-test setup-repo clean check-initial-tag helpt
5+
6+
7+
check-initial-tag:
8+
chmod u+x ./scripts/check-initial-tag.sh
9+
./scripts/check-initial-tag.sh
10+
11+
build:
12+
mkdir -p ./bin
13+
go build -o ./bin/brnchswppr ./cmd/branchswapper.go
14+
15+
setup-repo:
16+
chmod u+x ./scripts/setup-repo.sh
17+
./scripts/setup-repo.sh
18+
19+
test:
20+
go test -v -tags brnchswppr_test ./...
21+
22+
integration-test: build setup-repo
23+
export PATH
24+
chmod u+x ./scripts/test.sh
25+
./scripts/test.sh
26+
27+
clean:
28+
rm -rf ./tests || true

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,61 @@
1-
# branch-swap
1+
# branchswapper
2+
3+
Stash git branch names for later use.
4+
5+
6+
## Motivation (Dramatization)
7+
8+
Let's assume you have been working on a feature for the last couple of days and you have a feature branch for that..
9+
```shell
10+
➜ project $ git status
11+
On branch JIRA-TICKET-feature-with-a-very-long-name
12+
```
13+
14+
Suddenly, a wild bug/issue/support-ticket appears and you have to fix it `soon`. Typically, you switch to the branch where the problem popped up, branch out from it and start doing whatever you need to.
15+
```shell
16+
# Stash your current branch and checkout an existing branch
17+
➜ project $ branchswapper release/this-is-yet-not-a-stable-version
18+
19+
➜ project $ git status
20+
On branch release/this-is-yet-not-a-stable-version
21+
```
22+
23+
Some hours later, after closing that horrible bug you come back to the original feature branch you were working on. But, oh Lord, what was the name of the branch? Chill, we got your back..
24+
```shell
25+
# List your stashed branches
26+
➜ project $ branchswapper -ls
27+
0: JIRA-TICKET-feature-with-a-very-long-name
28+
29+
# Swap to the desired branch using the index assigned to it
30+
➜ project $ branchswapper -i 0
31+
32+
➜ project $ git status
33+
On branch JIRA-TICKET-feature-with-a-very-long-name
34+
```
35+
36+
37+
## Install
38+
39+
```shell
40+
➜ project $ go install github.com/grevych/branchswapper@latest
41+
```
42+
43+
44+
## Usage
45+
46+
```shell
47+
➜ project $ branchswapper -i 0
48+
NAME:
49+
branchswap - Stash git branches for later use
50+
51+
USAGE:
52+
branchswap [global options] command [command options]
53+
54+
COMMANDS:
55+
help, h Shows a list of commands or help for one command
56+
57+
GLOBAL OPTIONS:
58+
--list, --ls List stashed branches (default: false)
59+
--index value, -i value Swap branch by index (default: -1)
60+
--help, -h show help
61+
```

0 commit comments

Comments
 (0)