Fix habits and stargazers plugin, add repositories_affiliations options and metadata updates (#117)

This commit is contained in:
Simon Lecoq
2021-02-08 20:35:39 +01:00
committed by GitHub
parent cd83e85146
commit 3f0b9f96a6
31 changed files with 471 additions and 490 deletions

View File

@@ -1,5 +1,6 @@
name: "📰 Recent activity"
cost: 1 REST request per 100 events
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "🌸 Anilist"
cost: N/A
categorie: social
supports:
- user
- organization

View File

@@ -32,7 +32,8 @@ These are all enabled by default, but you can explicitely opt out from them.
- uses: lowlighter/metrics@latest
with:
# ... other options
base: header, repositories # Only display "header" and "repositories" sections
repositories: 100 # Query only last 100 repositories
repositories_forks: no # Don't include forks
base: header, repositories # Only display "header" and "repositories" sections
repositories: 100 # Query only last 100 repositories
repositories_forks: no # Don't include forks
repositories_affiliations: owner # Display only repositories where user is owner
```

View File

@@ -7,7 +7,7 @@
export default async function({login, graphql, data, q, queries, imports}, conf) {
//Load inputs
console.debug(`metrics/compute/${login}/base > started`)
let {repositories, repositories_forks:forks} = imports.metadata.plugins.base.inputs({data, q, account:"bypass"}, {repositories:conf.settings.repositories ?? 100})
let {repositories, "repositories.forks":forks, "repositories.affiliations":affiliations} = imports.metadata.plugins.base.inputs({data, q, account:"bypass"}, {repositories:conf.settings.repositories ?? 100})
//Skip initial data gathering if not needed
if (conf.settings.notoken)
@@ -23,7 +23,7 @@
try {
//Query data from GitHub API
console.debug(`metrics/compute/${login}/base > account ${account}`)
const queried = await graphql(queries.base[account]({login, "calendar.from":new Date(Date.now()-14*24*60*60*1000).toISOString(), "calendar.to":(new Date()).toISOString(), forks:forks ? "" : ", isFork: false"}))
const queried = await graphql(queries.base[account]({login, "calendar.from":new Date(Date.now()-14*24*60*60*1000).toISOString(), "calendar.to":(new Date()).toISOString(), forks:forks ? "" : ", isFork: false", affiliations:affiliations ? `, ownerAffiliations: ${affiliations.toLocaleUpperCase()}` : ""}))
Object.assign(data, {user:queried[account]})
postprocess?.[account]({login, data})
//Query repositories from GitHub API
@@ -33,7 +33,7 @@
let pushed = 0
do {
console.debug(`metrics/compute/${login}/base > retrieving repositories after ${cursor}`)
const {[account]:{repositories:{edges, nodes}}} = await graphql(queries.base.repositories({login, account, after:cursor ? `after: "${cursor}"` : "", repositories:Math.min(repositories, {user:100, organization:25}[account]), forks:forks ? "" : ", isFork: false"}))
const {[account]:{repositories:{edges, nodes}}} = await graphql(queries.base.repositories({login, account, after:cursor ? `after: "${cursor}"` : "", repositories:Math.min(repositories, {user:100, organization:25}[account]), forks:forks ? "" : ", isFork: false", affiliations:affiliations ? `, ownerAffiliations: ${affiliations.toLocaleUpperCase()}` : ""}))
cursor = edges?.[edges?.length-1]?.cursor
data.user.repositories.nodes.push(...nodes)
pushed = nodes.length

View File

@@ -1,5 +1,6 @@
name: "🗃️ Base content"
cost: 1 GraphQL request
categorie: core
supports:
- user
- organization
@@ -32,3 +33,13 @@ inputs:
description: Include forks in metrics
type: boolean
default: no
# Filter repositories by user affiliations
repositories_affiliations:
description: Repositories affiliations
type: string
default: ""
values:
- owner
- collaborator
- organization_member

View File

@@ -1,6 +1,6 @@
query BaseRepositories {
$account(login: "$login") {
repositories($after first: $repositories $forks, orderBy: {field: UPDATED_AT, direction: DESC}) {
repositories($after first: $repositories $forks $affiliations, orderBy: {field: UPDATED_AT, direction: DESC}) {
edges {
cursor
}

View File

@@ -8,7 +8,7 @@ query BaseUser {
websiteUrl
isHireable
twitterUsername
repositories(last: 0 $forks) {
repositories(last: 0 $forks $affiliations) {
totalCount
totalDiskUsage
nodes {

View File

@@ -1,5 +1,6 @@
name: "🧱 Core"
cost: N/A
categorie: core
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "🎟️ Follow-up of issues and pull requests"
cost: 0 API request
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "🎫 Gists"
cost: 1 GraphQL request per 100 gists
categorie: github
supports:
- user
inputs:

View File

@@ -100,7 +100,7 @@
console.debug(`metrics/compute/${login}/plugins > habits > running linguist`)
;(await imports.run(`${prefix} github-linguist --breakdown`, {cwd:path}))
//Parse linguist result
.split("\n").map(line => line.match(/(?<value>[\d.]+)%\s+(?<language>\w+)/)?.groups).filter(line => line)
.split("\n").map(line => line.match(/(?<value>[\d.]+)%\s+(?<language>[\s\S]+)$/)?.groups).filter(line => line)
.map(({value, language}) => habits.linguist.languages[language] = (habits.linguist.languages[language] ?? 0) + value/100)
habits.linguist.ordered = Object.entries(habits.linguist.languages).sort(([_an, a], [_bn, b]) => b - a)
}

View File

@@ -1,5 +1,6 @@
name: "💡 Coding habits"
cost: 1 REST request per 100 events + 1 REST request pet commit
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "📅 Isometric commit calendar"
cost: 2-3 REST requests
categorie: github
supports:
- user
inputs:

View File

@@ -1,5 +1,6 @@
name: "🈷️ Most used languages"
cost: 0 API request
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "👨‍💻 Lines of code changed"
cost: 1 REST request per repository
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "🎼 Music plugin"
cost: N/A
categorie: social
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "💉 Nightscout"
cost: N/A
categorie: health
supports:
- user
- organization
@@ -17,7 +18,7 @@ inputs:
type: string
default: https://example.herokuapp.com
# Controls how big the graph is
# Controls how big the graph is
plugin_nightscout_datapoints:
description: How many datapoints to show on the graph. 0 and 1 disable the graph.
type: number

View File

@@ -1,5 +1,6 @@
name: "⏱️ Website performances"
cost: N/A
categorie: social
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "🧑‍🤝‍🧑 People plugin"
cost: 1 GraphQL request per 100 users + 1 REST request per user in "plugin_people_thanks"
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "✒️ Recent posts"
cost: N/A
categorie: social
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "🗂️ Projects"
cost: 1 GraphQL request + 1 GraphQL request per repository project
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "✨ Stargazers over last weeks"
cost: 1 GraphQL request per 100 stargazers
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "🌟 Recently starred repositories"
cost: 1 GraphQL request
categorie: github
supports:
- user
inputs:

View File

@@ -1,5 +1,6 @@
name: "📌 Starred topics"
cost: N/A
categorie: github
supports:
- user
inputs:

View File

@@ -1,5 +1,6 @@
name: "🧮 Repositories traffic"
cost: 1 REST request per repository
categorie: github
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "🐤 Latest tweets"
cost: N/A
categorie: social
supports:
- user
- organization

View File

@@ -1,5 +1,6 @@
name: "⏰ WakaTime plugin"
cost: N/A
categorie: social
supports:
- user
inputs: