Skip to content

Instantly share code, notes, and snippets.

@imWildCat
Created December 13, 2023 19:46
Show Gist options
  • Save imWildCat/c65a2c01d7456355510c6c5b58ce404e to your computer and use it in GitHub Desktop.
Save imWildCat/c65a2c01d7456355510c6c5b58ce404e to your computer and use it in GitHub Desktop.
Unstar old Swift repos (no update for one year and less than 1k stars)
import axios from 'axios';
const GITHUB_TOKEN = 'xxx';
const GITHUB_USERNAME = 'xxx';
axios.defaults.headers.common['Authorization'] = `token ${GITHUB_TOKEN}`;
const unstarRepo = async (repoFullName: string) => {
try {
await axios.delete(`https://api.github.com/user/starred/${repoFullName}`);
console.log(`Unstarred ${repoFullName}`);
} catch (error) {
console.error(`Error unstarring ${repoFullName}: `, error);
}
};
const unstarSwiftRepos = async () => {
try {
let page = 1;
let shouldContinue = true;
while (shouldContinue) {
const response = await axios.get(`https://api.github.com/users/${GITHUB_USERNAME}/starred?per_page=100&page=${page}`);
const repos = response.data;
if (repos.length === 0) {
shouldContinue = false;
break;
}
for (const repo of repos) {
if (repo.language === 'Swift' && (repo.stargazers_count < 1000 || new Date(repo.updated_at) < new Date(Date.now() - 365 * 24 * 60 * 60 * 1000))) {
await unstarRepo(repo.full_name);
}
}
page++;
}
} catch (error) {
console.error('Error fetching repositories: ', error);
}
};
unstarSwiftRepos();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment