On Wed, 2017-10-04 at 11:49 +0200, Bertrand Delacretaz wrote:
> Hi,
>
> On Wed, Oct 4, 2017 at 9:57 AM, Robert Munteanu <[email protected]>
> wrote:
> > ...The 'canonical' way of doing this is by accessing https://api.gi
> > thub.co
> > m/orgs/${github_org}/repos and filtering based on the repo name...
>
> Note that this would require handling multiple pages, it looks like
> the max number of results is 200:
>
> $ curl -s "https://api.github.com/orgs/apache/repos?page=1&per_page=2
> 00"
> > grep html_url | wc -l
>
> 200
> $ curl -s "https://api.github.com/orgs/apache/repos?page=1&per_page=2
> 10"
> > grep html_url | wc -l
>
> 200
> $ curl -s "https://api.github.com/orgs/apache/repos?page=2&per_page=2
> 10"
> > grep html_url | wc -l
>
> 200
>
> But otherwise grabbing that is easy in our Groovy templates,
> something like:
>
> URL url = new URL("https://api.github.com/orgs/apache/repos?page=1&pe
> r_page=100")
> def json = new groovy.json.JsonSlurper().parseText(url.text)
> json.each ( {
> it ->
> if(it.full_name.contains("struts")) {
> println it.html_url
> }
> })
I'll just paste here the chunks script I've used so far. I won't link
to it since it's in the 'not-sling' org which will go away next week.
github_org="not-sling"
project_prefix="sling-"
curl_args="$1"
page_count=$(curl ${curl_args} -sI https://api.github.com/orgs/${github
_org}/repos | grep 'Link: ' | tr ',' '\n' | grep 'rel="last"' |
sed 's/.*page=\([0-9][0-9]*\).*/\1/')
for page in $(seq 1 ${page_count}); do
for repo in $(curl ${curl_args} -s https://api.github.com/orgs/${gi
thub_org}/repos?page=${page} \
| jq ".[] | .name | match (\"${project_prefix}.*\") | .string"
| tr -d '"' | sort); do
# your processing here
done
done
We can consider either creating a shared script for it or have a single
job which periodically regenerates a JSON file with all the projects.
Robert