From 8cba3f449a27d92dadbe95a3f4c44ac20f7d4714 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Wed, 14 Apr 2021 18:37:50 +0200 Subject: [PATCH] Disable additional affiliation constraint when used token is not from owner --- source/app/action/index.mjs | 1 + source/app/metrics/setup.mjs | 19 ++++++++++++++++--- source/app/web/statics/about/style.css | 5 +++++ source/plugins/base/index.mjs | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/source/app/action/index.mjs b/source/app/action/index.mjs index 6727b392..8ba579ec 100644 --- a/source/app/action/index.mjs +++ b/source/app/action/index.mjs @@ -122,6 +122,7 @@ authenticated = github.context.repo.owner } const user = _user || authenticated + conf.authenticated = user info("GitHub account", user) if (q.repo) info("GitHub repository", `${user}/${q.repo}`) diff --git a/source/app/metrics/setup.mjs b/source/app/metrics/setup.mjs index bcd401a4..95931bf6 100644 --- a/source/app/metrics/setup.mjs +++ b/source/app/metrics/setup.mjs @@ -5,6 +5,7 @@ import processes from "child_process" import util from "util" import url from "url" + import OctokitRest from "@octokit/rest" //Templates and plugins const Templates = {} @@ -26,6 +27,7 @@ const logger = log ? console.debug : () => null logger("metrics/setup > setup") const conf = { + authenticated:null, templates:{}, queries:{}, settings:{}, @@ -100,7 +102,7 @@ await fs.promises.rmdir(path.join(__templates, ".community"), {recursive:true}) logger(`metrics/setup > loaded community template ${name}`) } - catch (error) { + catch (error) { logger(`metrics/setup > failed to load community template ${template}`) logger(error) } @@ -195,10 +197,21 @@ //Load metadata (plugins) conf.metadata = await metadata({log}) + //Store authenticated user + if (conf.settings.token) { + try { + conf.authenticated = (await (new OctokitRest.Octokit({auth:conf.settings.token})).users.getAuthenticated()).data.login + logger(`metrics/setup > setup > authenticated as ${conf.authenticated}`) + } + catch (error) { + logger(`metrics/setup > setup > could not verify authentication : ${error}`) + } + } + //Set no token property Object.defineProperty(conf.settings, "notoken", {get() { - return conf.settings.token === "NOT_NEEDED" -}}) + return conf.settings.token === "NOT_NEEDED" + }}) //Conf logger("metrics/setup > setup > success") diff --git a/source/app/web/statics/about/style.css b/source/app/web/statics/about/style.css index 3b6f0f69..8990e845 100644 --- a/source/app/web/statics/about/style.css +++ b/source/app/web/statics/about/style.css @@ -148,6 +148,7 @@ } .activity .content { flex-grow: 1; + max-width: 95%; } .activity quote { display: block; @@ -156,6 +157,7 @@ border-radius: .25rem; border: 1px solid var(--color-border-secondary); color: var(--color-text-secondary); + overflow-x: auto; } .activity quote p:first-child { margin-top: 0; @@ -163,6 +165,9 @@ .activity quote p:last-child { margin-bottom: 0; } + .activity img { + max-width: 100%; + } /* User */ .user { diff --git a/source/plugins/base/index.mjs b/source/plugins/base/index.mjs index c7539827..8185bdeb 100644 --- a/source/plugins/base/index.mjs +++ b/source/plugins/base/index.mjs @@ -9,7 +9,7 @@ console.debug(`metrics/compute/${login}/base > started`) let {repositories, "repositories.forks":_forks, "repositories.affiliations":_affiliations} = imports.metadata.plugins.base.inputs({data, q, account:"bypass"}, {repositories:conf.settings.repositories ?? 100}) const forks = _forks ? "" : ", isFork: false" - const affiliations = _affiliations?.length ? `, ownerAffiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}], affiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]` : "" + const affiliations = _affiliations?.length ? `, ownerAffiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]${conf.authenticated === login ? `, affiliations: [${_affiliations.map(x => x.toLocaleUpperCase()).join(", ")}]` : ""}` : "" //Skip initial data gathering if not needed if (conf.settings.notoken)