Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 13 additions & 28 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
# Base image
FROM node:20-bookworm-slim
# Use original pre-built image as base (contains all dependencies)
# This avoids rebuilding Chrome, Node modules, etc. when only code changes
ARG BASE_IMAGE=ghcr.io/lowlighter/metrics:v3.35-beta
FROM ${BASE_IMAGE} as base

# Copy repository
COPY . /metrics
WORKDIR /metrics
# Copy only our changed files (GraphQL queries and JS code)
# This is much faster than rebuilding everything
COPY source/plugins/achievements/queries/achievements.graphql /metrics/source/plugins/achievements/queries/achievements.graphql
COPY source/plugins/achievements/queries/organizations.graphql /metrics/source/plugins/achievements/queries/organizations.graphql
COPY source/plugins/achievements/list/users.mjs /metrics/source/plugins/achievements/list/users.mjs
COPY source/plugins/achievements/list/organizations.mjs /metrics/source/plugins/achievements/list/organizations.mjs
COPY source/plugins/habits/index.mjs /metrics/source/plugins/habits/index.mjs

# Setup
RUN chmod +x /metrics/source/app/action/index.mjs \
# Install latest chrome dev package, fonts to support major charsets and skip chromium download on puppeteer install
# Based on https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker
&& apt-get update \
&& apt-get install -y wget gnupg ca-certificates libgconf-2-4 \
&& wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 libx11-xcb1 libxtst6 lsb-release --no-install-recommends \
# Install deno for miscellaneous scripts
&& apt-get install -y curl unzip \
&& curl -fsSL https://deno.land/x/install/install.sh | DENO_INSTALL=/usr/local sh \
# Install ruby to support github licensed gem
&& apt-get install -y ruby-full git g++ cmake pkg-config libssl-dev \
&& gem install licensed \
# Install python for node-gyp
&& apt-get install -y python3 \
# Clean apt/lists
&& rm -rf /var/lib/apt/lists/* \
# Install node modules and rebuild indexes
&& npm ci \
&& npm run build
# No need to rebuild - the base image already has everything installed
# Our code changes are just file replacements

# Environment variables
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
Expand Down
20 changes: 19 additions & 1 deletion action.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions source/plugins/achievements/list/organizations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ export default async function({list, login, data, computed, imports, graphql, qu

//Managers
{
const value = organization.projects.totalCount
const unlock = organization.projects.nodes?.shift()
const value = organization.projectsV2.totalCount
const unlock = organization.projectsV2.nodes?.shift()

list.push({
title: "Managers",
Expand Down
4 changes: 2 additions & 2 deletions source/plugins/achievements/list/users.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export default async function({list, login, data, computed, imports, graphql, qu

//Manager
{
const value = user.projects.totalCount
const unlock = user.projects.nodes?.shift()
const value = user.projectsV2.totalCount
const unlock = user.projectsV2.nodes?.shift()

list.push({
title: "Manager",
Expand Down
9 changes: 5 additions & 4 deletions source/plugins/achievements/queries/achievements.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ query AchievementsDefault {
totalCount
}
}
projects(first: 1, orderBy: {field: CREATED_AT, direction: ASC}) {
projectsV2(first: 1, orderBy: {field: CREATED_AT, direction: ASC}) {
totalCount
#nodes { This requires additional scopes :/
# name
#}
nodes {
createdAt
title
}
}
packages(first: 1, orderBy: {direction: ASC, field: CREATED_AT}) {
totalCount
Expand Down
6 changes: 5 additions & 1 deletion source/plugins/achievements/queries/organizations.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ query AchievementsOrganizations {
}
}
}
projects(first: 1, orderBy: {field: CREATED_AT, direction: ASC}) {
projectsV2(first: 1, orderBy: {field: CREATED_AT, direction: ASC}) {
totalCount
nodes {
createdAt
title
}
}
packages(first: 1, orderBy: {direction: ASC, field: CREATED_AT}) {
totalCount
Expand Down
26 changes: 23 additions & 3 deletions source/plugins/habits/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ export default async function({login, data, rest, imports, q, account}, {enabled
const patches = [
...await Promise.allSettled(
commits
.flatMap(({payload}) => payload.commits)
.filter(({author}) => data.shared["commits.authoring"].filter(authoring => author?.login?.toLocaleLowerCase().includes(authoring) || author?.email?.toLocaleLowerCase().includes(authoring) || author?.name?.toLocaleLowerCase().includes(authoring)).length)
.flatMap(({payload}) => payload?.commits ?? [])
.filter(commit => commit != null && typeof commit === 'object') // Filter out null/undefined commits and ensure it's an object
.filter(commit => {
// Safely check author property
const author = commit?.author
if (!author) return false
return data.shared["commits.authoring"].filter(authoring => author?.login?.toLocaleLowerCase().includes(authoring) || author?.email?.toLocaleLowerCase().includes(authoring) || author?.name?.toLocaleLowerCase().includes(authoring)).length
})
.map(async commit => (await rest.request(commit)).data.files),
),
]
Expand Down Expand Up @@ -139,7 +145,21 @@ export default async function({login, data, rest, imports, q, account}, {enabled
}
//Handle errors
catch (error) {
throw imports.format.error(error)
// Log the actual error for debugging
console.debug(`metrics/compute/${login}/plugins > habits > error:`, error)
console.debug(`metrics/compute/${login}/plugins > habits > error message:`, error.message)
console.debug(`metrics/compute/${login}/plugins > habits > error stack:`, error.stack)
throw imports.format.error(error, {
descriptions: {
custom(error) {
// Provide more specific error messages
if (error.message) return error.message
if (error.response?.data?.message) return error.response.data.message
if (error.response?.data?.errors?.[0]?.message) return error.response.data.errors[0].message
return null
}
}
})
}
}

Expand Down
Loading