Find active forks of a GitHub repository
Tags: git
Published: 2022-12-18 18:03:19

There are probably better ways to do it but I'm a big fan of `curl` and `awk`. This is a quick script to find who, on GitHub, has an active fork of a repo.

```sh
last_git_forks(){
for url in $(
curl -s "https://github.com/$1/network/members" |
awk -F '"' '/>'"${1#*/}"'</{print "https://github.com"$4}'
) ; do
curl -s $url/branches | tac | awk -F '"' '
/relative-time/{
 # gets the last update of the branch
 if ( $2 > lasttime ) { lasttime=$2 ; lastbranch=branch }
}
/Link to (.*) file tree/{
 # get the branch name
 branch=gensub(/Link to (.*) file tree[.]/,"\\1",1,$4)
}
END{
 if (lasttime>"") printf "%-24s %-15s %-s\n",lasttime, lastbranch, name
}
' xname="${url#*com/}" name=${url%/*}
done | sort
}
```

For example, I wanted to check the recent `pg_tle` that has been made public by AWS at last re:Invent
```sh
[Franck ~]$ last_git_forks aws/pg_tle

2022-11-30T23:04:58Z     main            https://github.com/brunnojcb
2022-11-30T23:04:58Z     main            https://github.com/jk-shah
2022-11-30T23:04:58Z     main            https://github.com/PawelMahooana
2022-11-30T23:04:58Z     main            https://github.com/richardsonjf
2022-11-30T23:04:58Z     main            https://github.com/rleibbrandt-aws
2022-12-14T05:00:47Z     main            https://github.com/aws
2022-12-14T05:00:47Z     main            https://github.com/robins
2022-12-16T10:58:40Z     dev             https://github.com/sharmay
2022-12-17T05:03:46Z     tap             https://github.com/formalLogicGirl


[Franck ~]$
```
I'm also interested to see how Babelfish (a project initiated by AWS to bring SQL Server compatibility to PostgreSQL) is popular:
```sh
[Franck ~]$ last_git_forks babelfish-for-postgresql/postgresql_modified_for_babelfish | tail -20

2022-04-11T08:09:35Z     BABEL_1_X_DEV__PG_13_6 https://github.com/HarshLunagariya
2022-04-20T12:07:21Z     BABEL_1_0_0__PG_13_4__distv2 https://github.com/ongres
2022-05-06T20:33:03Z     BABEL_2_X_DEV__PG_14_2 https://github.com/javainthinking
2022-05-06T20:33:03Z     issue_229       https://github.com/nasbyj
2022-05-11T13:58:50Z     BABEL_1_X_DEV__PG_13_6 https://github.com/KushaalShroff
2022-05-25T08:05:00Z     BABEL_2_X_DEV__PG_14_2 https://github.com/anju15bharti
2022-05-25T08:05:00Z     BABEL_2_X_DEV__PG_14_2 https://github.com/Terry1504
2022-06-30T07:24:33Z     BABEL_2_X_DEV__PG_14_3 https://github.com/reshke
2022-07-05T09:45:06Z     BABEL_2_X_DEV__PG_14_3 https://github.com/rohit01010
2022-07-25T23:23:05Z     BABEL_2_X_DEV__PG_14_2 https://github.com/Dhruvi-0802
2022-08-10T10:41:59Z     BABEL_2_X_DEV__PG_14_3 https://github.com/agattani190
2022-08-10T10:41:59Z     BABEL_2_X_DEV__PG_14_3 https://github.com/oscarno22
2022-08-10T10:41:59Z     BABEL_2_X_DEV__PG_14_3 https://github.com/thephantomthief
2022-09-15T04:59:35Z     BABEL_2_X_DEV__PG_14_5 https://github.com/qiuwenhuifx
2022-09-21T14:17:53Z     BABEL_2_X_DEV__PG_14_5 https://github.com/seo-kw
2022-11-07T21:38:53Z     BABEL_2_X_DEV__PG_14_X https://github.com/Bit-Quill
2022-11-17T23:26:00Z     BABEL_2_X_DEV__PG_14_X https://github.com/faizol
2022-12-06T18:14:22Z     BABEL_2_X_DEV__PG_14_X https://github.com/kuntalghosh
2022-12-17T08:59:05Z     BABEL_3_X_DEV__PG_15_X https://github.com/babelfish-for-postgresql
2022-12-18T14:01:23Z     code_coverage   https://github.com/amazon-aurora
```

This lists the last activity on a fork's branch. As any indicator of popularity, it gives an idea but do not take too strong decisions on that. An active fork may be short term and removed once a Pull Request is accepted.