Last active
March 14, 2023 19:27
-
-
Save HansKre/01a2da29287da7b79f74b2fd61fbfdb1 to your computer and use it in GitHub Desktop.
Git-API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('https'); | |
const PAT = ''; | |
const ORG_NAME = 'vpp'; | |
const makeRequest = (path, method, cb, data) => { | |
const options = { | |
method: method, | |
hostname: 'github.com', | |
port: null, | |
path: path, | |
headers: { | |
'user-agent': 'vscode-restclient', | |
authorization: `bearer ${PAT}`, | |
'content-type': 'application/json', | |
accept: 'application/json', | |
}, | |
}; | |
const req = http.request(options, function (res) { | |
const chunks = []; | |
res.on('data', function (chunk) { | |
chunks.push(chunk); | |
}); | |
res.on('end', function () { | |
const body = Buffer.concat(chunks); | |
cb(body); | |
}); | |
}); | |
if (data) { | |
req.write(JSON.stringify(data)); | |
} | |
req.end(); | |
}; | |
// retrieves all repos for $ORG_NAME and archives them | |
makeRequest( | |
`/api/v3/orgs/${ORG_NAME}/repos?page=1&per_page=100`, | |
'GET', | |
(repos) => { | |
console.log('Total number of repos in org', JSON.parse(repos).length); | |
const repoFullNames = JSON.parse(repos) | |
.filter((repo) => !repo.archived) | |
.map((repo) => repo.full_name); | |
console.log('repoFullNames', repoFullNames); | |
// archive all repos | |
console.log('Total number of repos to archive', repoFullNames.length); | |
repoFullNames.forEach((repoFullName) => { | |
makeRequest( | |
`/api/v3/repos/${repoFullName}`, | |
'PATCH', | |
(patchedRepo) => { | |
const jsonBody = JSON.parse(patchedRepo); | |
console.log(jsonBody.full_name, jsonBody.archived); | |
}, | |
{ archived: true } | |
); | |
}); | |
} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let added = 0; | |
let removed = 0; | |
document | |
.querySelectorAll( | |
'#files_bucket > diff-file-filter > diff-layout > div.pr-toolbar.js-sticky.js-position-sticky.d-flex > div > div.flex-auto.min-width-0 > div.d-flex.flex-items-center > details.details-reset.details-overlay.diffbar-item.toc-select.select-menu.ml-0.ml-sm-3 > details-menu > div.select-menu-list > div:nth-child(2) > a' | |
) | |
.forEach((row) => { | |
const fileName = row.querySelector('span.description').innerText; | |
if (fileName.includes('package-lock.json')) return; | |
const currentAdded = row | |
.querySelector('span.diffstat > span.color-fg-success') | |
.innerText.replace('+', '') | |
.replace(',', ''); | |
added = added + parseInt(currentAdded); | |
const currentRemoved = row | |
.querySelector('span.diffstat > span.color-fg-danger') | |
.innerText.replace('−', '') | |
.replace(',', ''); | |
removed = removed + parseInt(currentRemoved); | |
}); | |
console.error('added', added, 'removed', removed); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment