Metadata-Version: 2.1
Name: ccpr
Version: 1.0.0
Summary: AWS CodeCommit PR CLI
Home-page: https://github.com/rog555/ccpr
Author: Roger Foskett
Author-email: r_foskett@hotmail.com
License: Apache License 2.0
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
Requires-Dist: argcomplete (==1.12.3)
Requires-Dist: argh (==0.26.2)
Requires-Dist: boto3 (==1.21.31)
Requires-Dist: jmespath (==0.10.0)
Requires-Dist: rich (==12.0.1)
Requires-Dist: timeago (==1.0.15)

# AWS CodeCommit PR CLI

The **ccpr** script attempts to replicate the basic AWS CodeCommit Console from the CLI when dealing with pull requests.  It does abit more such as enable recursive remote repo searches and CodePipeline build status/linking

This is achieved via context of current working git repo and branch, a bit of commandline completion and rich colours!

**why?**

Using CodeCommit console in one account at same time as accessing console in another account can be a pain (yes, maybe incognito could work..)  CLI access should allow for quicker workflow for creating/reviewing/approving and merging PRs

[![Tests](https://github.com/rog555/ccpr/actions/workflows/tests.yml/badge.svg)](https://github.com/rog555/ccpr/actions/workflows/tests.yml/)
[![Codecov](https://codecov.io/gh/rog555/ccpr/branch/main/graph/badge.svg)](https://codecov.io/gh/rog555/ccpr/branch/main)

## Usage

```
usage: ccpr [-h]
    {approve,a,create,c,close,x,comment,C,diff,d,grep,g,merge,m,pipeline,p,pr,id,prs,ls,repos,r} ...

AWS CodeCommit PR CLI

positional arguments:
  {approve,a,create,c,close,x,comment,C,diff,d,grep,g,merge,m,pipeline,p,pr,id,prs,ls,repos,r}
    approve (a)         approve PR
    create (c)          create PR
    close (x)           close PR
    comment (C)         comment on PR, general if file and lineno not specified
    diff (d)            diff two local files
    grep (g)            grep the remote repo(s)
    merge (m)           merge PR
    pipeline (p)        show codepipeline status
    pr (id)             show details for specific PR (colorized diffs with comments etc)
    prs (ls)            list PRs for repo - OPEN by default
    repos (r)           list repos
```

## Installation

```
$ pip install ccpr
```

ccpr uses argcomplete for commandline completion, see https://kislyuk.github.io/argcomplete/#installation

### Zsh

Add the following to your ~/.zshrc file and start new terminal window once saved

```
autoload -U bashcompinit
bashcompinit
eval "$(register-python-argcomplete ccpr)"
```

### Bash

Add following to ~/.bash_profile and start new terminal window once saved

```
eval "$(register-python-argcomplete ccpr)"
```

## Authentication ##

See https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

Eg: 

```
export AWS_DEFAULT_PROFILE=devops-account
export AWS_DEFAULT_REGION=us-east-1
```

## Examples

### List repos

```
$ ccpr repos -f tool
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ name                                 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ developer-tools                      │
│ monitoring-tools                     │
│ some-other-tool                      │
└──────────────────────────────────────┘
```

### Create PR

Change to CodeCommit repo directory and create PR on the 'foobar' branch.  The latest commit message is used as default PR title

```
$ cd developer-tools/
$ git branch
  master
* foobar

$ ccpr create
Enter PR title (foobar baz biz fiz):
created PR 351
link: https://us-east-1.console.aws.amazon.com/codesuite/codecommit/repositories/developer-tools/pull-requests/351/changes?region=us-east-1
```

### List PRs in current repo

```
$ ccpr prs
┏━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ id  ┃ title              ┃ author        ┃ activity    ┃ status ┃ approvals              ┃
┡━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 351 │ foobar baz biz fiz │ foo@foo.com   │ 3 hours ago │ CLOSED │ 1 of 2 rules satisfied │
└─────┴────────────────────┴───────────────┴─────────────┴────────┴────────────────────────┘
```

### List details of PR

Show colorized diff

```
$ ccpr pr 351 -d
┏━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ id  ┃ title              ┃ author        ┃ activity    ┃ status ┃ approvals              ┃
┡━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
│ 351 │ foobar baz biz fiz │ foo@foo.com   │ 3 hours ago │ CLOSED │ 1 of 2 rules satisfied │
└─────┴────────────────────┴───────────────┴─────────────┴────────┴────────────────────────┘
some-file1.txt
────────────────────────────────────────────────────────────────────────────────────────────
   1    1:   abc
   2     : - def
        2: + defghi
   3     : - hij
        3: + xyz
        4: +
```

### Recursive grep across remote repos

```
$ ccpr grep -R -i baz '*.txt' --repo 'myrepo1,somerepo*'
myrepo1: /folder1/somefile1.txt:    fooBar
somerepo1: /folder1/somefile3.txt:    fooBar
somerepo1: /folder2/somefile4.txt:    FOOBAR
```


### Show Code Pipeline status

Depends how pipeline setup, but a sensible generic convention could be
in format `<repo>_<branch>`, if not use the `--name` option

Use `-m` for `master` branch, current repo will be used without `--name`

```
$ ccpr pipeline -m
┏━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓
┃ stage   ┃ status    ┃ updated             ┃ summary                 ┃ error ┃
┡━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━┩
│ source  │ Succeeded │ 2020-01-01T00:00:00 │ fix something           │       │
│ build   │ Succeeded │ 2020-01-01T00:00:00 │                         │       │
│ approve │ Succeeded │ 2020-01-01T00:00:00 │ Approved by foo@bar.com │       │
│ test    │ Succeeded │ 2020-01-01T00:00:00 │                         │ ohno! │
└─────────┴───────────┴─────────────────────┴─────────────────────────┴───────┘
```

## License

The license is Apache 2.0, see [LICENSE](./LICENSE) for the details.

