feat: extend homepage.js with collaborators fetch

These are not implemented everywhere so I have to handle errors here.
But for what we want to build right now (projects overview) they are.

Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
This commit is contained in:
André Jaenisch 2024-06-15 12:23:21 +02:00
parent 662dc71ede
commit 0581a55c92
No known key found for this signature in database
GPG key ID: 5A668E771F1ED854

View file

@ -52,7 +52,13 @@ export async function getHomepage({ account, passphrase, server }) {
const s = await fetchFollowings(loginFormData, getCookie(r), person); const s = await fetchFollowings(loginFormData, getCookie(r), person);
const followings = getFollowingsFromResponse(s); const followings = getFollowingsFromResponse(s);
const t = await fetchFollowingsMap(loginFormData, getCookie(s), followings); const t = await fetchFollowingsMap(loginFormData, getCookie(s), followings);
const followingsMap = getFollowingsMapFromRsponses(t); const followingsMap = getFollowingsMapFromResponses(t);
const u = await fetchFollowingsCollaborators(
loginFormData,
getCookie(t[t.length - 1]),
followingsMap
);
const collaboratorsMap = getFollowingsCollabotorsFromResponses(u);
if (dom('h2:contains("Your teams") + p').text().includes("aren't a member")) { if (dom('h2:contains("Your teams") + p').text().includes("aren't a member")) {
console.log('No teams'); console.log('No teams');
@ -81,7 +87,8 @@ export async function getHomepage({ account, passphrase, server }) {
} }
return { return {
cookies: getCookie(t[t.length - 1]), collaboratorsMap,
cookies: getCookie(u[u.length - 1]),
followings, followings,
followingsMap, followingsMap,
person, person,
@ -118,7 +125,11 @@ function getFollowingsFromResponse(response) {
return response.data; return response.data;
} }
function getFollowingsMapFromRsponses(responses) { function getFollowingsMapFromResponses(responses) {
return responses.map((response) => response.data);
}
function getFollowingsCollabotorsFromResponses(responses) {
return responses.map((response) => response.data); return responses.map((response) => response.data);
} }
@ -161,3 +172,28 @@ async function fetchFollowingsMap(loginFormData, cookie, followings) {
return Promise.all(mappedFollowings); return Promise.all(mappedFollowings);
} }
async function fetchFollowingsCollaborators(loginFormData, cookie, followingsMap) {
const headers = new AxiosHeaders();
headers.set({ Cookie: cookie });
const mappedCollaborators = followingsMap.map(async (following) => {
const { pathname } = new URL(following.collaborators);
let response = null;
try {
response = await loginFormData.instance.get(pathname, { headers });
} catch (exc) {
// Repo Collaborators is not implemented yet
response = {
data: {
items: [],
details: exc.response.data.error
}
};
}
return response;
});
return Promise.all(mappedCollaborators);
}