Skip to content

Commit

Permalink
Merge pull request #1 from talex5/improve-summary
Browse files Browse the repository at this point in the history
Better output for zero or one repositories
  • Loading branch information
talex5 authored Feb 25, 2020
2 parents 92990ab + ff44fac commit 861e70c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ 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.
```

This renders as:

> 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 All @@ -25,3 +43,10 @@ au BufRead,BufNewFile **/log.md map \a G:r! github-activity<CR>
```

Then `\a` (in normal mode) will paste recent activity at the end of the file.

Tip: if you want to be able to open the URLs it adds in a browser, you can use something like this:

```vim
" gx to open URLs in Firefox
let g:netrw_browsex_viewer= "firefox"
```
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 861e70c

Please sign in to comment.