People plugin : repository template support (#78)
This commit is contained in:
@@ -239,7 +239,7 @@
|
||||
if (plugins.people.enabled) {
|
||||
for (const option of ["limit", "size"])
|
||||
info(`People ${option}`, q[`people.${option}`] = input.number(`plugin_people_${option}`))
|
||||
for (const option of ["types"])
|
||||
for (const option of ["types", "thanks"])
|
||||
info(`People ${option}`, q[`people.${option}`] = input.array(`plugin_people_${option}`))
|
||||
for (const option of ["identicons"])
|
||||
info(`People ${option}`, q[`people.${option}`] = input.bool(`plugin_people_${option}`))
|
||||
|
||||
@@ -362,7 +362,7 @@
|
||||
}) : ({
|
||||
user:{
|
||||
[type]:{
|
||||
edges:new Array(Math.ceil(20+80*Math.random())).fill(undefined).map((login = faker.internet.userName()) => ({
|
||||
edges:new Array(Math.ceil(20+80*Math.random())).fill(null).map((login = faker.internet.userName()) => ({
|
||||
cursor:"MOCKED_CURSOR",
|
||||
node:{
|
||||
login,
|
||||
@@ -373,6 +373,66 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
//People query (repositories)
|
||||
if (/^query PeopleRepository /.test(query)) {
|
||||
console.debug(`metrics/compute/mocks > mocking graphql api result > People`)
|
||||
const type = query.match(/(?<type>stargazers|watchers)[(]/)?.groups?.type ?? "(unknown type)"
|
||||
return /after: "MOCKED_CURSOR"/m.test(query) ? ({
|
||||
user:{
|
||||
repository:{
|
||||
[type]:{
|
||||
edges:[],
|
||||
}
|
||||
}
|
||||
}
|
||||
}) : ({
|
||||
user:{
|
||||
repository:{
|
||||
[type]:{
|
||||
edges:new Array(Math.ceil(20+80*Math.random())).fill(null).map((login = faker.internet.userName()) => ({
|
||||
cursor:"MOCKED_CURSOR",
|
||||
node:{
|
||||
login,
|
||||
avatarUrl:null,
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
//People sponsors query
|
||||
if (/^query PeopleSponsors /.test(query)) {
|
||||
console.debug(`metrics/compute/mocks > mocking graphql api result > People`)
|
||||
const type = query.match(/(?<type>sponsorshipsAsSponsor|sponsorshipsAsMaintainer)[(]/)?.groups?.type ?? "(unknown type)"
|
||||
return /after: "MOCKED_CURSOR"/m.test(query) ? ({
|
||||
user:{
|
||||
login,
|
||||
[type]:{
|
||||
edges:[]
|
||||
}
|
||||
}
|
||||
}) : ({
|
||||
user:{
|
||||
login,
|
||||
[type]:{
|
||||
edges:new Array(Math.ceil(20+80*Math.random())).fill(null).map((login = faker.internet.userName()) => ({
|
||||
cursor:"MOCKED_CURSOR",
|
||||
node:{
|
||||
sponsorEntity:{
|
||||
login:faker.internet.userName(),
|
||||
avatarUrl:null,
|
||||
},
|
||||
sponsorable:{
|
||||
login:faker.internet.userName(),
|
||||
avatarUrl:null,
|
||||
}
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
//Unmocked call
|
||||
return target(...args)
|
||||
}
|
||||
@@ -389,6 +449,8 @@
|
||||
getViews:rest.repos.getViews,
|
||||
getContributorsStats:rest.repos.getContributorsStats,
|
||||
listCommits:rest.repos.listCommits,
|
||||
listContributors:rest.repos.listContributors,
|
||||
getByUsername:rest.users.getByUsername,
|
||||
}
|
||||
|
||||
//Raw request
|
||||
@@ -893,6 +955,49 @@
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
//Repository contributors
|
||||
rest.repos.listContributors = new Proxy(unmocked.listContributors, {
|
||||
apply:function(target, that, [{owner, repo}]) {
|
||||
console.debug(`metrics/compute/mocks > mocking rest api result > rest.repos.listContributors`)
|
||||
return ({
|
||||
status:200,
|
||||
url:`https://api.github.com/repos/${owner}/${repo}/contributors`,
|
||||
headers: {
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:new Array(40+faker.random.number(60)).fill(null).map(() => ({
|
||||
login:faker.internet.userName(),
|
||||
avatar_url:null,
|
||||
contributions:faker.random.number(1000),
|
||||
}))
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
//User informations
|
||||
rest.users.getByUsername = new Proxy(unmocked.getByUsername, {
|
||||
apply:function(target, that, [{username}]) {
|
||||
console.debug(`metrics/compute/mocks > mocking rest api result > rest.repos.getByUsername`)
|
||||
return ({
|
||||
status:200,
|
||||
url:`'https://api.github.com/users/${username}/`,
|
||||
headers: {
|
||||
server:"GitHub.com",
|
||||
status:"200 OK",
|
||||
"x-oauth-scopes":"repo",
|
||||
},
|
||||
data:{
|
||||
login:faker.internet.userName(),
|
||||
avatar_url:null,
|
||||
contributions:faker.random.number(1000),
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
//Axios mocking
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
stars:"🌟 Recently starred repositories",
|
||||
stargazers:"✨ Stargazers over last weeks",
|
||||
activity:"📰 Recent activity",
|
||||
people:"🧑🤝🧑 Followers and followed",
|
||||
people:"🧑🤝🧑 People",
|
||||
anilist:"🌸 Anilist",
|
||||
base:"🗃️ Base content",
|
||||
"base.header":"Header",
|
||||
@@ -120,6 +120,7 @@
|
||||
"people.size":{text:"Limit", type:"number", min:16, max:64},
|
||||
"people.limit":{text:"Limit", type:"number", min:1, max:9999},
|
||||
"people.types":{text:"Types", placeholder:"followers, following"},
|
||||
"people.thanks":{text:"Special thanks", placeholder:"user1, user2, ..."},
|
||||
"people.identicons":{text:"Use identicons", type:"boolean"},
|
||||
"anilist.medias":{text:"Medias to display", placeholder:"anime, manga"},
|
||||
"anilist.sections":{text:"Sections to display", placeholder:"favorites, watching, reading, characters"},
|
||||
@@ -157,6 +158,7 @@
|
||||
"people.size":28,
|
||||
"people.limit":28,
|
||||
"people.types":"followers, following",
|
||||
"people.thanks":"",
|
||||
"people.identicons":false,
|
||||
"anilist.medias":"anime, manga",
|
||||
"anilist.sections":"favorites",
|
||||
|
||||
@@ -222,17 +222,25 @@
|
||||
}) : null),
|
||||
//People
|
||||
...(set.plugins.enabled.people ? ({
|
||||
people:{
|
||||
types:options["people.types"].split(",").map(x => x.trim()),
|
||||
size:options["people.size"],
|
||||
followers:new Array(Number(options["people.limit"])).fill(null).map(_ => ({
|
||||
login:faker.internet.userName(),
|
||||
avatar:"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==",
|
||||
})),
|
||||
following:new Array(Number(options["people.limit"])).fill(null).map(_ => ({
|
||||
login:faker.internet.userName(),
|
||||
avatar:"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==",
|
||||
}))
|
||||
get people() {
|
||||
const types = options["people.types"].split(",").map(x => x.trim())
|
||||
.map(x => ({followed:"following", sponsors:"sponsorshipsAsMaintainer", sponsored:"sponsorshipsAsSponsor", sponsoring:"sponsorshipsAsSponsor"})[x] ?? x)
|
||||
.filter(x => ["followers", "following", "sponsorshipsAsMaintainer", "sponsorshipsAsSponsor"].includes(x))
|
||||
return {
|
||||
types,
|
||||
size:options["people.size"],
|
||||
...(Object.fromEntries(types.map(type => [
|
||||
type,
|
||||
new Array(Number(options["people.limit"])).fill(null).map(_ => ({
|
||||
login:faker.internet.userName(),
|
||||
avatar:"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==",
|
||||
}))
|
||||
]))),
|
||||
thanks:options["people.thanks"].split(",").map(x => x.trim()).map(login => ({
|
||||
login,
|
||||
avatar:"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOcOnfpfwAGfgLYttYINwAAAABJRU5ErkJggg==",
|
||||
}))
|
||||
}
|
||||
}
|
||||
}) : null),
|
||||
//Music
|
||||
|
||||
Reference in New Issue
Block a user