Skip to content

Commit

Permalink
feat: specify git username and email on the command line
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanholsteijn committed Mar 25, 2022
1 parent a4bb8a8 commit 45ce792
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ git repository, without requiring complete write access to the repository.

## Usage
```
cru list [--verbose] [--no-filename] [--repository=URL [--branch=BRANCH]] [PATH] ...
cru update [--verbose] [--dry-run] [(--resolve-digest|--resolve-tag)] [--repository=URL [--branch=BRANCH] [--commit=MESSAGE]] (--all | --image-reference=REFERENCE ...) [PATH] ...
cru serve [--verbose] [--dry-run] [--port=PORT] --repository=URL --branch=BRANCH [PATH] ...
Usage:
cru list [--verbose] [--no-filename] [--repository=URL [--branch=BRANCH] [(--username=USERNAME --email=EMAIL)] ] [PATH] ...
cru update [--verbose] [--dry-run] [(--resolve-digest|--resolve-tag)] [--repository=URL [--branch=BRANCH] [(--username=USERNAME --email=EMAIL)] [--commit=MESSAGE]] (--all | --image-reference=REFERENCE ...) [PATH] ...
cru serve [--verbose] [--dry-run] [--port=PORT] --repository=URL --branch=BRANCH [(--username=USERNAME --email=EMAIL)] [PATH] ...
```

## Options
Expand All @@ -32,6 +33,8 @@ git repository, without requiring complete write access to the repository.
--commit=MESSAGE commit the changes with the specified message.
--repository=URL to read and/or update.
--branch=BRANCH to update.
--username=USERNAME to use for the commit [default: cru].
--email=EMAIL to use for the commit [default: cru@binx.io].
--port=PORT to listen on, defaults to 8080 or PORT environment variable.
```
Expand Down Expand Up @@ -132,3 +135,4 @@ To install you have a number of different options:
- cru is not context-aware: anything that looks like a container image references is updated.
- cru will ignore any references to unqualified official images, like docker:latest or nginx:3. To update the official docker image references, prefix them with docker.io/ or docker.io/library/.
- the time to find the alternate tag is proportional to the number of tags associated with the image.
- the default git commit username and email is cru / cru@binx.io. It is not taken from gitconfig.
4 changes: 2 additions & 2 deletions committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func (c *Cru) Commit() (hash plumbing.Hash, err error) {
if !c.DryRun {
hash, err = c.workTree.Commit(c.CommitMsg, &git.CommitOptions{
Author: &object.Signature{
Name: "cru",
Email: "cru@binx.io",
Name: c.Username,
Email: c.Email,
When: time.Now(),
},
})
Expand Down
21 changes: 18 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Cru struct {
Url string `docopt:"--repository"`
CommitMsg string `docopt:"--commit"`
Branch string `docopt:"--branch"`
Username string
Email string
imageRefs ref.ContainerImageReferences
updatedFiles []string
committedFiles []string
Expand Down Expand Up @@ -178,13 +180,23 @@ func (c *Cru) ConnectToRepository() error {
return nil
}

func (c *Cru) ApplyDefaults() {
if c.Username == "" {
c.Username = "cru"
}

if c.Email == "" {
c.Email = "cru@binx.io"
}
}

func main() {
usage := `cru - container image reference updater
Usage:
cru list [--verbose] [--no-filename] [--repository=URL [--branch=BRANCH]] [PATH] ...
cru update [--verbose] [--dry-run] [(--resolve-digest|--resolve-tag)] [--repository=URL [--branch=BRANCH] [--commit=MESSAGE]] (--all | --image-reference=REFERENCE ...) [PATH] ...
cru serve [--verbose] [--dry-run] [--port=PORT] --repository=URL --branch=BRANCH [PATH] ...
cru list [--verbose] [--no-filename] [--repository=URL [--branch=BRANCH] [(--username=USERNAME --email=EMAIL)] ] [PATH] ...
cru update [--verbose] [--dry-run] [(--resolve-digest|--resolve-tag)] [--repository=URL [--branch=BRANCH] [(--username=USERNAME --email=EMAIL)] [--commit=MESSAGE]] (--all | --image-reference=REFERENCE ...) [PATH] ...
cru serve [--verbose] [--dry-run] [--port=PORT] --repository=URL --branch=BRANCH [(--username=USERNAME --email=EMAIL)] [PATH] ...
Options:
--no-filename do not print the filename.
Expand All @@ -197,6 +209,8 @@ Options:
--commit=MESSAGE commit the changes with the specified message.
--repository=URL to read and/or update.
--branch=BRANCH to update.
--username=USERNAME to use for the commit [default: cru].
--email=EMAIL to use for the commit [default: cru@binx.io].
--port=PORT to listen on, defaults to 8080 or PORT environment variable.
`
cru := Cru{}
Expand All @@ -209,6 +223,7 @@ Options:
if err = args.Bind(&cru); err != nil {
log.Fatal(err)
}
cru.ApplyDefaults()

if err = cru.ConnectToRepository(); err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 45ce792

Please sign in to comment.