feat: fetch commits from Vervis
I had to hardcode the path to the commits because it is not a property on the repository object. There are empty repositories, which I handle as well. Next step is displaying them in the Activities. Signed-off-by: André Jaenisch <andre.jaenisch@posteo.de>
This commit is contained in:
parent
288ad752ad
commit
d3fc06a239
1 changed files with 144 additions and 12 deletions
|
@ -47,18 +47,86 @@ export async function getHomepage({ account, passphrase, server }) {
|
||||||
const dom = cheerio.load(response.data);
|
const dom = cheerio.load(response.data);
|
||||||
const inbox = getInboxLinkFromResponse(response);
|
const inbox = getInboxLinkFromResponse(response);
|
||||||
const peopleId = getPeopleIdFromInboxLink(inbox);
|
const peopleId = getPeopleIdFromInboxLink(inbox);
|
||||||
const r = await fetchPersonData(loginFormData, getCookie(response), peopleId);
|
const a = await fetchPersonData(loginFormData, getCookie(response), peopleId);
|
||||||
const person = getPersonFromResponse(r);
|
const person = getPersonFromResponse(a);
|
||||||
const s = await fetchFollowings(loginFormData, getCookie(r), person);
|
const b = await fetchFollowings(loginFormData, getCookie(a), person);
|
||||||
const followings = getFollowingsFromResponse(s);
|
const followings = getFollowingsFromResponse(b);
|
||||||
const t = await fetchFollowingsMap(loginFormData, getCookie(s), followings);
|
const c = await fetchFollowingsMap(loginFormData, getCookie(b), followings);
|
||||||
const followingsMap = getFollowingsMapFromResponses(t);
|
const followingsMap = getFollowingsMapFromResponses(c);
|
||||||
const u = await fetchFollowingsCollaborators(
|
const d = await fetchFollowingsCollaborators(
|
||||||
loginFormData,
|
loginFormData,
|
||||||
getCookie(t[t.length - 1]),
|
getCookie(c[c.length - 1]),
|
||||||
followingsMap
|
followingsMap
|
||||||
);
|
);
|
||||||
const collaboratorsMap = getFollowingsCollabotorsFromResponses(u);
|
const collaboratorsMap = getFollowingsCollabotorsFromResponses(d);
|
||||||
|
// Have to update cookies from one request to the next
|
||||||
|
let temp = d[d.length - 1];
|
||||||
|
const e = await Promise.all(
|
||||||
|
followingsMap
|
||||||
|
.filter((following) => following.type === 'Repository')
|
||||||
|
.map(async (repository) => {
|
||||||
|
const resp = await fetchCommitsForRepository(
|
||||||
|
loginFormData,
|
||||||
|
getCookie(temp),
|
||||||
|
repository.id,
|
||||||
|
'main'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (resp.headers) {
|
||||||
|
temp = resp;
|
||||||
|
} else {
|
||||||
|
temp = {
|
||||||
|
...temp,
|
||||||
|
...resp
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const commits = getCommitsFromResponses(e);
|
||||||
|
const f = await fetchCommitsMap(loginFormData, getCookie(temp), commits);
|
||||||
|
const commitsMap = getCommitsMapFromResponses(f);
|
||||||
|
|
||||||
|
// fr33domlover = qn870 on fig.fr33domlover.site
|
||||||
|
const g = await fetchPersonData(loginFormData, getCookie(temp), 'qn870');
|
||||||
|
const otherPerson = getPersonFromResponse(g);
|
||||||
|
const h = await fetchFollowings(loginFormData, getCookie(g), otherPerson);
|
||||||
|
const otherFollowings = getFollowingsFromResponse(h);
|
||||||
|
const i = await fetchFollowingsMap(loginFormData, getCookie(h), otherFollowings);
|
||||||
|
const otherFollowingsMap = getFollowingsMapFromResponses(i);
|
||||||
|
const j = await fetchFollowingsCollaborators(
|
||||||
|
loginFormData,
|
||||||
|
getCookie(i[i.length - 1]),
|
||||||
|
otherFollowingsMap
|
||||||
|
);
|
||||||
|
const otherCollaboratorsMap = getFollowingsCollabotorsFromResponses(j);
|
||||||
|
|
||||||
|
temp = i[i.length - 1];
|
||||||
|
const k = await Promise.all(
|
||||||
|
otherFollowingsMap
|
||||||
|
.filter((following) => following.type === 'Repository')
|
||||||
|
.map(async (repository) => {
|
||||||
|
const resp = await fetchCommitsForRepository(
|
||||||
|
loginFormData,
|
||||||
|
getCookie(temp),
|
||||||
|
repository.id,
|
||||||
|
'main'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (resp.headers) {
|
||||||
|
temp = resp;
|
||||||
|
} else {
|
||||||
|
temp = {
|
||||||
|
...temp,
|
||||||
|
...resp
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return resp;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const otherCommits = getCommitsFromResponses(k);
|
||||||
|
const l = await fetchCommitsMap(loginFormData, getCookie(temp), otherCommits);
|
||||||
|
const otherCommitsMap = getCommitsMapFromResponses(l);
|
||||||
|
|
||||||
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');
|
||||||
|
@ -87,11 +155,15 @@ export async function getHomepage({ account, passphrase, server }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
collaboratorsMap,
|
collaboratorsMap: [...collaboratorsMap, ...otherCollaboratorsMap],
|
||||||
cookies: getCookie(u[u.length - 1]),
|
commits: [...commits, ...otherCommits],
|
||||||
|
commitsMap: [...commitsMap, ...otherCommitsMap],
|
||||||
|
cookies: getCookie(temp),
|
||||||
followings,
|
followings,
|
||||||
followingsMap,
|
otherFollowings,
|
||||||
|
followingsMap: [...followingsMap, ...otherFollowingsMap],
|
||||||
person,
|
person,
|
||||||
|
otherPerson,
|
||||||
patches,
|
patches,
|
||||||
projects,
|
projects,
|
||||||
repos,
|
repos,
|
||||||
|
@ -133,6 +205,14 @@ function getFollowingsCollabotorsFromResponses(responses) {
|
||||||
return responses.map((response) => response.data);
|
return responses.map((response) => response.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCommitsFromResponses(responses) {
|
||||||
|
return responses.map((response) => response.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCommitsMapFromResponses(responses) {
|
||||||
|
return responses.map((response) => response.data);
|
||||||
|
}
|
||||||
|
|
||||||
function getPeopleIdFromInboxLink(inboxLink) {
|
function getPeopleIdFromInboxLink(inboxLink) {
|
||||||
// The id is part of the pathname as /people/:peopleId/inbox
|
// The id is part of the pathname as /people/:peopleId/inbox
|
||||||
const url = new URL(inboxLink);
|
const url = new URL(inboxLink);
|
||||||
|
@ -197,3 +277,55 @@ async function fetchFollowingsCollaborators(loginFormData, cookie, followingsMap
|
||||||
|
|
||||||
return Promise.all(mappedCollaborators);
|
return Promise.all(mappedCollaborators);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchCommitsForRepository(loginFormData, cookie, repository, branch) {
|
||||||
|
const headers = new AxiosHeaders();
|
||||||
|
headers.set({ Cookie: cookie });
|
||||||
|
|
||||||
|
const { pathname } = new URL(repository);
|
||||||
|
let response = null;
|
||||||
|
try {
|
||||||
|
response = await loginFormData.instance.get(`${pathname}/commits-by/${branch}?page=1`, {
|
||||||
|
headers
|
||||||
|
});
|
||||||
|
} catch (exc) {
|
||||||
|
// Can turn out to be 404 Not Found
|
||||||
|
response = {
|
||||||
|
...exc.response,
|
||||||
|
data: {
|
||||||
|
orderedItems: [],
|
||||||
|
details: exc.response.data.message
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchCommitsMap(loginFormData, cookie, commits) {
|
||||||
|
const headers = new AxiosHeaders();
|
||||||
|
headers.set({ Cookie: cookie });
|
||||||
|
|
||||||
|
const mappedCommits = commits
|
||||||
|
.map((commit) => {
|
||||||
|
return commit.orderedItems.map(async (c) => {
|
||||||
|
const { pathname } = new URL(c);
|
||||||
|
let response = null;
|
||||||
|
try {
|
||||||
|
response = await loginFormData.instance.get(pathname, { headers });
|
||||||
|
} catch (exc) {
|
||||||
|
// Can turn out to be 500 Internal Server Error
|
||||||
|
response = {
|
||||||
|
...exc.response,
|
||||||
|
data: {
|
||||||
|
details: exc.response.data.error
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.flat(1);
|
||||||
|
|
||||||
|
return Promise.all(mappedCommits);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue