snapshotizr

Create monthly team diff from GHE repositories

Usage no npm install needed!

<script type="module">
  import snapshotizr from 'https://cdn.skypack.dev/snapshotizr';
</script>

README

Snapshotizr

Snapshot creates a diff for each project modified by your team members on Github.

Slack channel: #STP-Snapshotizr

Setup

Install and initialise snapshotizr:

npm install -g snapshotizr
snapshotizr-init

Create a github token with scope: repo and edit configuration file: ~/snapshotizr/config.js.

Enjoy! :)

FTP upload

If you want snapshotizr to automatically upload generated diffs (aka. reports) to your FTP server, please provide "ftp" object with following fields to the config file:

ftp: {
  host: '192.168.x.x',
  user: 'username',
  remoteRoot: '/public_dir/some_subdir/'
}

Password is not required in the config file - if nothing given, you'll be prompted for it during execution time.

Slack notifications

If you want to receive success and failure notifications on Slack, please provide a "slack" object with following fields in the config file:

slack: {
  enabled: true,
  token: 'SLACK_TOKEN',
  channel: 'CHANNEL_ID',
},

You need to create a Slack application to get the token needed here. Creating a Slack app in the sch-chat workspace requires admin approval, but is easy to get. I suggest having a single Slack app per team and just re-use it for all integrations. Scope required here is chat:write (you need to add the app to your channel first).

To get a channel ID it's easiest to open Slack in the browser, enter the desired channel and pick its ID from URL e.g. https://app.slack.com/client/T0356Q2CJ/C044Q8M5W <-- C044Q8M5W is the channel ID.

Working directory

Default

Snapshotizr uses directory: ~/snapshotizr/.

Custom

You can use file ~/.snapshotizr for configuration and also add there key 'appDir' in root with appropriate path to define working directory (for repositories and reports)

Usage

Just run:

snapshotizr -h

to see available options:

  -f, --from date       Date string, default value: start of this month
  -u, --until date      Date string, default value: now
  -s, --skip-cleanup    Do not remove cloned repositories at the end of the script
  -c, --config string   Configuration file path
  -h, --help            Print this help message

Example - generate report since 2021-01-25 up to now:

snapshotizr --from 2021-01-25

Limitations

Supported protocols

This tool support only HTTPS protocol to work with Git.

Limited number of public events in GHE

Github provides only last 100 public events performed by a user (event == push, not commit). So in the specific situation, you can lose some repos.

To work around that you can explicitly specify repos inside config.profiles in configuration file, for example:

const config = { 
  appDir: '',
  skipCleanup: true,
  profiles: [
    {   
      name: 'ghe',
      repos: ['snt/fastenposten', 'snt/snt-capi-preview'],
      ...

it is also possible to exclude specific repositories from processing:

const config = { 
  appDir: '',
  skipCleanup: true,
  profiles: [
    {   
      name: 'ghe',
      reposToSkip: ['spt-privacy/jakub-test', 'spt/adventofcode' ],
      ...

Generating report for Jira

Besides storing a code snapshot we're all required to create Jira issues inside 'Copyright' project with a human-readable report listing all work delivered this month present in the snapshot (in Polish).

Here's a snippet to make this work easier. It takes your push messages and translates them using Google Translate. I highly suggest going through it afterwards, there are often beauties in there e.g. 'fix lint' ==> 'napraw kłaczki' 😂 Still, it's faster and more detailed than writing it from scratch.

npm i -g git-standup google-translate-cli
git standup -m 3 -A "`date +%Y-%m-01` 00:00:00" -D short -s | grep '<IMIE_NAZWISKO>' | cut -f3- -d" " | rev | cut -d" " -f4- | rev | translate -s en -t pl
  • replace date param with a proper date matching from param set for snapshotizr, e.g. git standup -m 3 -A "2021-01-25 00:00:00" ...
  • adjust git standup params to fit the way you have your projects stored locally.
  • <IMIE_NAZWISKO> is spelled normally e.g. 'Wojciech Iskra'

How to publish package to NpmJS

Package is published to NpmJS when NPM tag is created.

You can bump version using command npm version.

Example:

npm version patch
npm version minor
npm version major

When new version will be created code need to pushed to master:

git push --tags