Skip to content

Instantly share code, notes, and snippets.

@salman0ansari
Created May 6, 2026 09:47
Show Gist options
  • Select an option

  • Save salman0ansari/8e22f37331696f76eaa9994f10c50f2e to your computer and use it in GitHub Desktop.

Select an option

Save salman0ansari/8e22f37331696f76eaa9994f10c50f2e to your computer and use it in GitHub Desktop.
manage github stars lists
import ky from 'ky';
export const createGitHubListClient = ({ username, cookie, authenticityToken }) => {
const api = ky.create({
prefixUrl: 'https://github.com',
headers: {
cookie,
'x-requested-with': 'XMLHttpRequest',
origin: 'https://github.com',
referer: `https://github.com/${username}?tab=stars`
}
});
const withToken = (fd) => {
fd.append('authenticity_token', authenticityToken);
return fd;
};
return {
checkListName: async (name) => {
const fd = new FormData();
fd.append('value', name);
return api.post(`stars/${username}/list-check`, {
searchParams: { attr: 'name' },
body: withToken(fd)
}).text();
},
createList: async (name, description = '', isPrivate = false) => {
const fd = new FormData();
fd.append('user_list[name]', name);
fd.append('user_list[description]', description);
fd.append('user_list[private]', '0');
if (isPrivate) fd.append('user_list[private]', '1');
return api.post(`stars/${username}/lists`, {
body: withToken(fd)
}).text();
},
updateList: async (listSlug, newName, newDescription = '', isPrivate = false) => {
const fd = new FormData();
fd.append('_method', 'put');
fd.append('user_list[name]', newName);
fd.append('user_list[description]', newDescription);
fd.append('user_list[private]', '0');
if (isPrivate) fd.append('user_list[private]', '1');
return api.post(`stars/${username}/lists/${listSlug}`, {
body: withToken(fd)
}).text();
},
deleteList: async (listSlug) => {
const fd = new FormData();
fd.append('_method', 'delete');
return api.post(`stars/${username}/lists/${listSlug}`, {
body: withToken(fd)
}).text();
},
manageRepoLists: async (repoOwner, repoName, repoId, listIds = []) => {
const fd = new FormData();
fd.append('_method', 'put');
fd.append('repository_id', repoId.toString());
fd.append('context', 'user_list_menu');
fd.append('user_list_menu_dirty', '1');
for (const listId of listIds) {
fd.append('list_ids[]', listId.toString());
}
return api.post(`${repoOwner}/${repoName}/lists`, {
body: withToken(fd)
}).text();
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment