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:
parent
662dc71ede
commit
0581a55c92
1 changed files with 39 additions and 3 deletions
|
@ -52,7 +52,13 @@ export async function getHomepage({ account, passphrase, server }) {
|
|||
const s = await fetchFollowings(loginFormData, getCookie(r), person);
|
||||
const followings = getFollowingsFromResponse(s);
|
||||
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")) {
|
||||
console.log('No teams');
|
||||
|
@ -81,7 +87,8 @@ export async function getHomepage({ account, passphrase, server }) {
|
|||
}
|
||||
|
||||
return {
|
||||
cookies: getCookie(t[t.length - 1]),
|
||||
collaboratorsMap,
|
||||
cookies: getCookie(u[u.length - 1]),
|
||||
followings,
|
||||
followingsMap,
|
||||
person,
|
||||
|
@ -118,7 +125,11 @@ function getFollowingsFromResponse(response) {
|
|||
return response.data;
|
||||
}
|
||||
|
||||
function getFollowingsMapFromRsponses(responses) {
|
||||
function getFollowingsMapFromResponses(responses) {
|
||||
return responses.map((response) => response.data);
|
||||
}
|
||||
|
||||
function getFollowingsCollabotorsFromResponses(responses) {
|
||||
return responses.map((response) => response.data);
|
||||
}
|
||||
|
||||
|
@ -161,3 +172,28 @@ async function fetchFollowingsMap(loginFormData, cookie, followings) {
|
|||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue