Skip to content

Commit

Permalink
Merge branch 'release/v1.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kilpkonn committed Mar 24, 2021
2 parents fbf089b + 2e4c69c commit 5d884ac
Show file tree
Hide file tree
Showing 10 changed files with 247 additions and 33 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
APP_NAME: 'gtm-core'
MAINTAINER: 'kilpkonn'
DESC: 'Seamless time tracking for git.'
DEPENDS: 'libssh2-1'
steps:
- name: Install Go
uses: actions/setup-go@v2
Expand Down Expand Up @@ -69,13 +70,14 @@ jobs:
cp $GOPATH/src/github.com/DEVELOPEST/gtm-core/build/gtm .debpkg/usr/bin
chmod +x .debpkg/usr/bin
- name: Build deb package
uses: jiro4989/build-deb-action@v2
uses: kilpkonn/build-deb-action@e8822c2bc4e1dbc5b898522a860eeab46b90776d
with:
package: ${{ env.APP_NAME }}
package_root: .debpkg
maintainer: ${{ env.MAINTAINER }}
version: ${{ github.event.inputs.release_version }}
arch: 'amd64'
depends: ${{ env.DEPENDS }}
desc: ${{ env.DESC }}
- name: Upload deb package
uses: actions/upload-artifact@v2
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/remove-old-artifacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Remove old artifacts

on:
schedule:
# Every day at 1am
- cron: '0 1 * * *'

jobs:
remove-old-artifacts:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Remove old artifacts
uses: c-hive/gha-remove-artifacts@v1
with:
age: '1 week'
# Optional inputs
skip-tags: true
skip-recent: 3
67 changes: 67 additions & 0 deletions command/rewrite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package command

import (
"bufio"
"github.com/DEVELOPEST/gtm-core/project"
"github.com/DEVELOPEST/gtm-core/scm"
"io"
"log"
"os"
"strings"

"github.com/mitchellh/cli"
)

// CommitCmd struct contain methods for commit command
type RewriteCmd struct {
UI cli.Ui
}

// NewCommit returns new CommitCmd struct
func NewRewrite() (cli.Command, error) {
return RewriteCmd{}, nil
}

// Help returns help for commit command
func (c RewriteCmd) Help() string {
helpText := `
Usage: gtm rewrite [options]
Automatically called on git history rewrite. Do not use manually!.
`
return strings.TrimSpace(helpText)
}

// Run executes commit commands with args
func (c RewriteCmd) Run(args []string) int {

reader := bufio.NewReader(os.Stdin)
for {
input, err := reader.ReadString('\n')
if err != nil {
if err != io.EOF {
log.Fatal(err)
}
break
}
input = strings.TrimSpace(input)
hashes := strings.Split(input, " ")

if len(hashes) < 2 {
log.Fatal("Unexpected input!")
}

err = scm.RewriteNote(hashes[0], hashes[1], project.NoteNameSpace)

if err != nil {
log.Fatal(err)
}
}

return 0
}

// Synopsis return help for commit command
func (c RewriteCmd) Synopsis() string {
return "Update git notes on history rewrite"
}
51 changes: 51 additions & 0 deletions command/rewrite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package command

import (
"github.com/DEVELOPEST/gtm-core/util"
"github.com/mitchellh/cli"
"log"
"os"
"strings"
"testing"
)

func TestRewriteDefaultOptions(t *testing.T) {
repo := util.NewTestRepo(t, false)
defer repo.Remove()
repo.Seed()
err := os.Chdir(repo.Workdir())
if err != nil {
log.Fatal(err)
}

(RewriteCmd{UI: new(cli.MockUi)}).Run([]string{})

ui := new(cli.MockUi)
c := RewriteCmd{UI: ui}

var args []string
rc := c.Run(args)

// TODO: Write to stdin

if rc != 0 {
t.Errorf("gtm rewrite(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter.String())
}
}

func TestRewriteInvalidOption(t *testing.T) {
ui := new(cli.MockUi)
c := RewriteCmd{UI: ui}

args := []string{"-invalid"}
rc := c.Run(args)

// TODO: Write to stdin

if rc != 1 {
t.Errorf("gtm rewrite(%+v), want 0 got %d, %s", args, rc, ui.ErrorWriter)
}
if !strings.Contains(ui.OutputWriter.String(), "Usage:") {
t.Errorf("gtm rewrite(%+v), want 'Usage:' got %d, %s", args, rc, ui.OutputWriter.String())
}
}
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func main() {
UI: ui,
}, nil
},
"rewrite": func() (cli.Command, error) {
return &command.RewriteCmd{
UI: ui,
}, nil
},
}

exitStatus, err := c.Run()
Expand Down
2 changes: 1 addition & 1 deletion metric/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func Process(interim bool, projPath ...string) (note.CommitNote, error) {
return note.CommitNote{}, err
}

if err := scm.CreateNote(note.Marshal(commitNote), project.NoteNameSpace); err != nil {
if err := scm.CreateNote(note.Marshal(commitNote), project.NoteNameSpace, ""); err != nil {
return note.CommitNote{}, err
}
if err := saveAndPurgeMetrics(gtmPath, metricMap, commitMap, readonlyMap); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion note/note.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func UnMarshal(s string) (CommitNote, error) {
}

default:
return CommitNote{}, fmt.Errorf("Unable to unmarshal time logged, unknown version %s", version)
continue // Ignore errors in syntax
}
}
sort.Sort(sort.Reverse(FileByTime(files)))
Expand Down
2 changes: 1 addition & 1 deletion project/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (i *Index) path() (string, error) {
if err != nil {
return "", err
}
return filepath.Join(u.HomeDir, ".gtm", "project.json"), nil
return filepath.Join(u.HomeDir, ".config", "gtm", "project.json"), nil
}

func (i *Index) load() error {
Expand Down
17 changes: 11 additions & 6 deletions project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ var (
Command: "gtm commit --yes",
RE: regexp.MustCompile(`(?s)[/:a-zA-Z0-9$_=()"\.\|\-\\ ]*gtm(.exe"|)\s+commit\s+--yes\.*`),
},
"post-rewrite": {
Exe: "gtm",
Command: "gtm rewrite",
RE: regexp.MustCompile(
`(?s)[/:a-zA-Z0-9$_=()"\.\|\-\\ ]*gtm\s+rewrite\.*`),
},
}
// GitConfig is map of git configuration settings
GitConfig = map[string]string{
"alias.pushgtm": "push origin refs/notes/gtm-data",
"alias.fetchgtm": "fetch origin refs/notes/gtm-data:refs/notes/gtm-data",
"notes.rewriteRef": "refs/notes/gtm-data",
"notes.rewriteMode": "concatenate",
"notes.rewrite.rebase": "true",
"notes.rewrite.amend": "true"}
"alias.pushgtm": "push origin refs/notes/gtm-data",
"alias.fetchgtm": "fetch origin refs/notes/gtm-data:refs/notes/gtm-data"}
// GitIgnore is file ignore to apply to git repo
GitIgnore = "/.gtm/"

Expand Down Expand Up @@ -323,6 +325,9 @@ func Uninitialize() (string, error) {
if err := scm.RemoveHooks(GitHooks, gitRepoPath); err != nil {
return "", err
}
if err := scm.RemoveHooks(GitPushRefsHooks, gitRepoPath); err != nil {
return "", err
}
if err := scm.ConfigRemove(GitConfig, gitRepoPath); err != nil {
return "", err
}
Expand Down
Loading

0 comments on commit 5d884ac

Please sign in to comment.