Skip to content

Commit

Permalink
fixed issue with page parsing phetsims/special-ops#181
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpen committed Apr 8, 2021
1 parent aa0af7d commit 91574b2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion github-labels/change-label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fi

binDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
creds=`node ${binDir}/printGithubAuthorization.js`
./update-repos-list.sh
node ./update-repos-list.js

echo 'For each repo, this script should print "200 OK" to indicate success'
echo 'If a 404 Not Found is printed, that repo is likely missing the standard label set.'
Expand Down
2 changes: 1 addition & 1 deletion github-labels/delete-label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fi
binDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
creds=`node ${binDir}/printGithubAuthorization.js`

./update-repos-list.sh
node ./update-repos-list.js

echo 'For each repo, this script should print "204 No Content" to indicate success'

Expand Down
2 changes: 1 addition & 1 deletion github-labels/new-label-all-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fi
binDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
creds=`node ${binDir}/printGithubAuthorization.js`

./update-repos-list.sh
node ./update-repos-list.js

echo 'For each repo, this script should print "201 Created" to indicate success"'

Expand Down
2 changes: 1 addition & 1 deletion github-labels/new-repo-add-labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ echo $1
binDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
creds=`node ${binDir}/printGithubAuthorization.js`

./update-repos-list.sh
node ./update-repos-list.js

echo 'For each repo, this script should print "200 OK", "201 Created" or "204 No Content" to indicate success.'
echo '"422 Unprocessable Entity" indicates an attempt to duplicate a label and can be ignored.'
Expand Down
6 changes: 6 additions & 0 deletions github-labels/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"dependencies": {
"axios": "^0.21.1",
"fs": "^0.0.1-security"
}
}
50 changes: 50 additions & 0 deletions github-labels/update-repos-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2021, University of Colorado Boulder

// update-repos-list.js
//
// This script creates a file in this directly called `.repos` that is
// a newline separated list of all repos in the phetsims organization.

const axios = require( 'axios' );
const buildLocal = require( '../../perennial/js/common/buildLocal' );
const fs = require( 'fs' );

let a;

( async () => {
// temporarily store the old repos for troubleshooting if problems arise
try {
await fs.promises.rename( '.repos', '.repos.old' );
}
catch( err ) {
if ( err.code !== 'ENOENT' ) {
console.error( err );
throw err;
}
}

// Iterate over all repos in the organization
let currentRepos;
let repoNames = '';
let currentPage = 1;
const pageSize = 100;
do {
currentRepos = ( await axios.get( `https://api.github.com/orgs/phetsims/repos?per_page=${pageSize}&page=${currentPage}&sort=full_name`, {
auth: {
username: buildLocal.developerGithubUsername,
password: buildLocal.developerGithubAccessToken
}
} ) ).data;
if ( currentRepos ) {
repoNames += currentRepos.map( repo => repo.name ).join( '\n' ) + '\n';
}
currentPage++;
} while ( currentRepos && currentRepos.length === pageSize );

// Save to disk
await fs.promises.writeFile( '.repos', repoNames );

// Clean up
await fs.promises.unlink( '.repos.old' );
} )();

0 comments on commit 91574b2

Please sign in to comment.