<commit_before>#+TITLE: Github layer

[[file:img/github.png]]

* Table of Contents                                         :TOC_4_gh:noexport:
 - [[#description][Description]]
   - [[#features][Features:]]
 - [[#install][Install]]
   - [[#layer][Layer]]
   - [[#git-configuration][Git configuration]]
 - [[#key-bindings][Key Bindings]]
   - [[#magit-gh-pulls][magit-gh-pulls]]
   - [[#gistel][gist.el]]
   - [[#clone-repositories][Clone repositories]]
   - [[#browse-files][Browse files]]

* Description
This layers adds support for [[http://github.com][Github]].

** Features:
- [[https://github.com/sigma/magit-gh-pulls][magit-gh-pulls]]: handy =magit= add-on to manage Github pull requests.
- [[https://github.com/defunkt/gist.el][gist.el]]: full-featured mode to browse and post Github gists.
- [[https://github.com/osener/github-browse-file][github-browse-file]] and [[https://github.com/sshaw/git-link][git-link]]: quickly browse github URL in your
  browser.
- [[https://github.com/dgtized/github-clone.el][Github clone]] allows for easy cloning and forking of repositories.

* Install
** Layer
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =github= to the existing =dotspacemacs-configuration-layers= list in this
file.

** Git configuration
You will need to generate a [[https://github.com/settings/tokens][personal access token]] on GitHub. This token should
have the =gist= and =repo= permissions. Once this token is created, it needs to
be added to your =~/.gitconfig=

#+BEGIN_SRC sh
  git config --global github.oauth-token <token>
#+END_SRC

* Key Bindings
** magit-gh-pulls

In a =magit status= buffer (~SPC g s~):

| Key Binding | Description                                     |
|-------------+-------------------------------------------------|
| ~# c~       | create a pull request                           |
| ~# g~       | get a list of all PRs in the current repository |
| ~# f~       | fetch the commits associated to the current PR  |
| ~# b~       | create a branch for the current PR              |
| ~# m~       | merge the PR with current branch                |

Note that =magit-gh-pulls= will try to fast-forward the PRs whenever it is
possible.

** gist.el

| Key Binding | Description                                   |
|-------------+-----------------------------------------------|
| ~SPC g g b~ | create a public gist with the buffer content  |
| ~SPC g g B~ | create a private gist with the buffer content |
| ~SPC g g l~ | open the gist list buffer                     |
| ~SPC g g r~ | create a public gist with the region content  |
| ~SPC g g R~ | create a private gist with the region content |

In the gist list buffer:

| Key Binding | Description                  |
|-------------+------------------------------|
| ~/~         | evil search                  |
| ~+~         | add buffer to gist           |
| ~-~         | remove file for gist         |
| ~b~ or ~o~  | open current gist in browser |
| ~f~         | fetch current gist           |
| ~g~         | refresh the list             |
| ~h~         | go left                      |
| ~j~         | go down                      |
| ~k~         | go up                        |
| ~K~         | kill current gist            |
| ~l~         | go right                     |
| ~n~         | next search occurrence       |
| ~N~         | next previous occurrence     |
| ~v~         | =visual state=               |
| ~V~         | =visual-line state=          |
| ~y~         | print URL and copy it        |

** Clone repositories

| Key Binding   | Description                                              |
|---------------+----------------------------------------------------------|
| ~SPC g h c /~ | search for a repository to clone it                      |
| ~SPC g h c c~ | clone and optionally fork repository                     |
| ~SPC g h c r~ | add a remote that is an existing fork of selected remote |
| ~SPC g h c f~ | fork remote in current user namespace                    |
| ~SPC g h c u~ | add upstream as remote                                   |

** Browse files

| Key Binding | Description                                                        |
|-------------+--------------------------------------------------------------------|
| ~SPC g h o~ | browse to file on github                                           |
<commit_msg>Fix magit-gh-pulls docs<commit_after>#+TITLE: Github layer

[[file:img/github.png]]

* Table of Contents                                         :TOC_4_gh:noexport:
 - [[#description][Description]]
   - [[#features][Features:]]
 - [[#install][Install]]
   - [[#layer][Layer]]
   - [[#git-configuration][Git configuration]]
 - [[#key-bindings][Key Bindings]]
   - [[#magit-gh-pulls][magit-gh-pulls]]
   - [[#gistel][gist.el]]
   - [[#clone-repositories][Clone repositories]]
   - [[#browse-files][Browse files]]

* Description
This layers adds support for [[http://github.com][Github]].

** Features:
- [[https://github.com/sigma/magit-gh-pulls][magit-gh-pulls]]: handy =magit= add-on to manage Github pull requests.
- [[https://github.com/defunkt/gist.el][gist.el]]: full-featured mode to browse and post Github gists.
- [[https://github.com/osener/github-browse-file][github-browse-file]] and [[https://github.com/sshaw/git-link][git-link]]: quickly browse github URL in your
  browser.
- [[https://github.com/dgtized/github-clone.el][Github clone]] allows for easy cloning and forking of repositories.

* Install
** Layer
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =github= to the existing =dotspacemacs-configuration-layers= list in this
file.

** Git configuration
You will need to generate a [[https://github.com/settings/tokens][personal access token]] on GitHub. This token should
have the =gist= and =repo= permissions. Once this token is created, it needs to
be added to your =~/.gitconfig=

#+BEGIN_SRC sh
  git config --global github.oauth-token <token>
#+END_SRC

* Key Bindings
** magit-gh-pulls

In a =magit status= buffer (~SPC g s~):

| Key Binding | Description                                                 |
|-------------+-------------------------------------------------------------|
| ~# c~       | create a pull request                                       |
| ~# r~       | get a list of (or reload) all PRs in the current repository |
| ~# f~       | fetch the commits associated to the current PR at point     |
| ~# b~       | create a branch for the current PR at point                 |
| ~# m~       | merge the PR with current branch at point                   |
| ~# d~       | show a diff of the current pull request at point            |

Note that =magit-gh-pulls= will try to fast-forward the PRs whenever it is
possible.

** gist.el

| Key Binding | Description                                   |
|-------------+-----------------------------------------------|
| ~SPC g g b~ | create a public gist with the buffer content  |
| ~SPC g g B~ | create a private gist with the buffer content |
| ~SPC g g l~ | open the gist list buffer                     |
| ~SPC g g r~ | create a public gist with the region content  |
| ~SPC g g R~ | create a private gist with the region content |

In the gist list buffer:

| Key Binding | Description                  |
|-------------+------------------------------|
| ~/~         | evil search                  |
| ~+~         | add buffer to gist           |
| ~-~         | remove file for gist         |
| ~b~ or ~o~  | open current gist in browser |
| ~f~         | fetch current gist           |
| ~g~         | refresh the list             |
| ~h~         | go left                      |
| ~j~         | go down                      |
| ~k~         | go up                        |
| ~K~         | kill current gist            |
| ~l~         | go right                     |
| ~n~         | next search occurrence       |
| ~N~         | next previous occurrence     |
| ~v~         | =visual state=               |
| ~V~         | =visual-line state=          |
| ~y~         | print URL and copy it        |

** Clone repositories

| Key Binding   | Description                                              |
|---------------+----------------------------------------------------------|
| ~SPC g h c /~ | search for a repository to clone it                      |
| ~SPC g h c c~ | clone and optionally fork repository                     |
| ~SPC g h c r~ | add a remote that is an existing fork of selected remote |
| ~SPC g h c f~ | fork remote in current user namespace                    |
| ~SPC g h c u~ | add upstream as remote                                   |

** Browse files

| Key Binding | Description                                                        |
|-------------+--------------------------------------------------------------------|
| ~SPC g h o~ | browse to file on github                                           |

{'fraction_non_alphanumeric': 0.18408736349453977, 'fraction_numerical': 0.00022286605749944285, 'mean_word_length': 1.4100429645542427, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4427565', 'n_tokens_mistral': 2501, 'n_tokens_neox': 2388, 'n_words': 843}