Skip to content

Commit

Permalink
Better output for zero or one repositories
Browse files Browse the repository at this point in the history
If there is no activity, display a suitable message.
If only one repository has activity, don't add a heading for it.
  • Loading branch information
talex5 committed Feb 25, 2020
1 parent 92990ab commit 0b927b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ The idea is that you keep a journal (e.g. `log.md`) and instead of manually copy
into it, you just run a command in your text editor and it pastes in everything you did since the last
paste. You can then edit this text as required.

For example, after creating this repository and making a PR against it, I type `\a` in Vim and it inserts:

```
Created repository [talex5/get-activity](https://github.com/talex5/get-activity).
Better output for zero or one repositories [#1](https://github.com/talex5/get-activity/pull/1).
If there is no activity, display a suitable message. If only one repository
has activity, don't add a heading for it.
```

## Activity sources

At the moment, GitHub activity is the only source it queries.
Expand Down
20 changes: 12 additions & 8 deletions contributions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,17 @@ let pp_body f = function
| body -> Fmt.pf f " @,@[<hov>%a@]" Fmt.words body

let pp_item f t =
Fmt.pf f "@[<v>%a%a@]" pp_title t pp_body t.body
Fmt.pf f "@[<v>%a.%a@]" pp_title t pp_body t.body

let pp_repo f (name, items) =
Fmt.pf f "### %s@,@,%a" name Fmt.(list ~sep:(cut ++ cut) pp_item) items

let items_by_repo ~from json =
let t = of_json ~from:(to_8601 from) json in
Repo_map.bindings t
let pp_items = Fmt.(list ~sep:(cut ++ cut) pp_item)

let pp ~from = Fmt.(using (items_by_repo ~from) (list ~sep:(cut ++ cut) pp_repo))
let pp_repo f (name, items) =
Fmt.pf f "### %s@,@,%a" name pp_items items

let pp ~from f json =
let from = to_8601 from in
let by_repo = Repo_map.bindings @@ of_json ~from json in
match by_repo with
| [] -> Fmt.pf f "(no activity found since %s)" from
| [(_, items)] -> pp_items f items
| repos -> Fmt.(list ~sep:(cut ++ cut)) pp_repo f repos

0 comments on commit 0b927b2

Please sign in to comment.