From 4e1174ea6399ac12d7e0b2cfad2e03ac5f71afa0 Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Wed, 17 Feb 2021 19:58:57 +0100 Subject: [PATCH] Add introduction plugin (#127) --- .../graphql/introduction.organization.mjs | 9 ++++++ .../graphql/introduction.repository.mjs | 9 ++++++ .../api/github/graphql/introduction.user.mjs | 9 ++++++ source/app/web/statics/app.placeholder.js | 8 +++++ source/plugins/introduction/README.md | 26 ++++++++++++++++ source/plugins/introduction/index.mjs | 31 +++++++++++++++++++ source/plugins/introduction/metadata.yml | 20 ++++++++++++ .../introduction/queries/organization.graphql | 5 +++ .../introduction/queries/repository.graphql | 5 +++ .../plugins/introduction/queries/user.graphql | 5 +++ source/plugins/introduction/tests.yml | 12 +++++++ source/templates/classic/partials/_.json | 1 + .../classic/partials/introduction.ejs | 26 ++++++++++++++++ source/templates/classic/style.css | 6 ++++ source/templates/repository/partials/_.json | 1 + .../repository/partials/introduction.ejs | 26 ++++++++++++++++ 16 files changed, 199 insertions(+) create mode 100644 source/app/mocks/api/github/graphql/introduction.organization.mjs create mode 100644 source/app/mocks/api/github/graphql/introduction.repository.mjs create mode 100644 source/app/mocks/api/github/graphql/introduction.user.mjs create mode 100644 source/plugins/introduction/README.md create mode 100644 source/plugins/introduction/index.mjs create mode 100644 source/plugins/introduction/metadata.yml create mode 100644 source/plugins/introduction/queries/organization.graphql create mode 100644 source/plugins/introduction/queries/repository.graphql create mode 100644 source/plugins/introduction/queries/user.graphql create mode 100644 source/plugins/introduction/tests.yml create mode 100644 source/templates/classic/partials/introduction.ejs create mode 100644 source/templates/repository/partials/introduction.ejs diff --git a/source/app/mocks/api/github/graphql/introduction.organization.mjs b/source/app/mocks/api/github/graphql/introduction.organization.mjs new file mode 100644 index 00000000..ba0dc1fe --- /dev/null +++ b/source/app/mocks/api/github/graphql/introduction.organization.mjs @@ -0,0 +1,9 @@ +/**Mocked data */ + export default function({faker, query, login = faker.internet.userName()}) { + console.debug("metrics/compute/mocks > mocking graphql api result > introduction/organization") + return ({ + organization:{ + description:faker.lorem.sentences(), + }, + }) + } diff --git a/source/app/mocks/api/github/graphql/introduction.repository.mjs b/source/app/mocks/api/github/graphql/introduction.repository.mjs new file mode 100644 index 00000000..b9692649 --- /dev/null +++ b/source/app/mocks/api/github/graphql/introduction.repository.mjs @@ -0,0 +1,9 @@ +/**Mocked data */ + export default function({faker, query, login = faker.internet.userName()}) { + console.debug("metrics/compute/mocks > mocking graphql api result > introduction/repository") + return ({ + repository:{ + description:faker.lorem.sentences(), + }, + }) + } diff --git a/source/app/mocks/api/github/graphql/introduction.user.mjs b/source/app/mocks/api/github/graphql/introduction.user.mjs new file mode 100644 index 00000000..8dcb6741 --- /dev/null +++ b/source/app/mocks/api/github/graphql/introduction.user.mjs @@ -0,0 +1,9 @@ +/**Mocked data */ + export default function({faker, query, login = faker.internet.userName()}) { + console.debug("metrics/compute/mocks > mocking graphql api result > introduction/user") + return ({ + user:{ + bio:faker.lorem.sentences(), + }, + }) + } diff --git a/source/app/web/statics/app.placeholder.js b/source/app/web/statics/app.placeholder.js index a04906c9..02156fab 100644 --- a/source/app/web/statics/app.placeholder.js +++ b/source/app/web/statics/app.placeholder.js @@ -175,6 +175,14 @@ comments:faker.random.number(1000) } }) : null), + //Introduction + ...(set.plugins.enabled.introduction ? ({ + introduction:{ + mode:"user", + title:options["introduction.title"], + text:faker.lorem.sentences(), + } + }) : null), //Languages ...(set.plugins.enabled.languages ? ({ languages:{ diff --git a/source/plugins/introduction/README.md b/source/plugins/introduction/README.md new file mode 100644 index 00000000..f0c826b4 --- /dev/null +++ b/source/plugins/introduction/README.md @@ -0,0 +1,26 @@ +### 🙋 Introduction + +The *introduction* plugin display your account bio or your organization/repository description. +It is mostly intended for metrics used outside of GitHub, since these informations are already available on GitHub. + + + +
+ +
Repository version + +
+ +
+ +#### â„šī¸ Examples workflows + +[âžĄī¸ Available options for this plugin](metadata.yml) + +```yaml +- uses: lowlighter/metrics@latest + with: + # ... other options + plugin_introduction: yes + plugin_introduction_title: no # Hide section title +``` \ No newline at end of file diff --git a/source/plugins/introduction/index.mjs b/source/plugins/introduction/index.mjs new file mode 100644 index 00000000..69a1a390 --- /dev/null +++ b/source/plugins/introduction/index.mjs @@ -0,0 +1,31 @@ +//Setup + export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false} = {}) { + //Plugin execution + try { + //Check if plugin is enabled and requirements are met + if ((!enabled)||(!q.introduction)) + return null + + //Load inputs + let {title} = imports.metadata.plugins.introduction.inputs({data, account, q}) + + //Context + let context = {mode:account, login} + if (q.repo) { + console.debug(`metrics/compute/${login}/plugins > people > switched to repository mode`) + const {owner, repo} = data.user.repositories.nodes.map(({name:repo, owner:{login:owner}}) => ({repo, owner})).shift() + context = {...context, mode:"repository", owner, repo} + } + + //Querying API + console.debug(`metrics/compute/${login}/plugins > introduction > querying api`) + const text = (await graphql(queries.introduction[context.mode](context)))[context.mode][{user:"bio", organization:"description", repository:"description"}[context.mode]] + + //Results + return {mode:context.mode, title, text} + } + //Handle errors + catch (error) { + throw {error:{message:"An error occured", instance:error}} + } + } \ No newline at end of file diff --git a/source/plugins/introduction/metadata.yml b/source/plugins/introduction/metadata.yml new file mode 100644 index 00000000..214092cd --- /dev/null +++ b/source/plugins/introduction/metadata.yml @@ -0,0 +1,20 @@ +name: "🙋 Introduction" +cost: 1 GraphQL request +categorie: github +supports: + - user + - organization + - repository +inputs: + + # Enable or disable plugin + plugin_introduction: + description: Display account or repository introduction + type: boolean + default: no + + # Display introduction section title + plugin_introduction_title: + description: Display introduction section title + type: boolean + default: yes \ No newline at end of file diff --git a/source/plugins/introduction/queries/organization.graphql b/source/plugins/introduction/queries/organization.graphql new file mode 100644 index 00000000..a0e8093b --- /dev/null +++ b/source/plugins/introduction/queries/organization.graphql @@ -0,0 +1,5 @@ +query IntroductionOrganization { + organization(login: "$login") { + description + } +} \ No newline at end of file diff --git a/source/plugins/introduction/queries/repository.graphql b/source/plugins/introduction/queries/repository.graphql new file mode 100644 index 00000000..0d5c8d77 --- /dev/null +++ b/source/plugins/introduction/queries/repository.graphql @@ -0,0 +1,5 @@ +query IntroductionRepository { + repository(name: "$repo", owner: "$owner") { + description + } +} \ No newline at end of file diff --git a/source/plugins/introduction/queries/user.graphql b/source/plugins/introduction/queries/user.graphql new file mode 100644 index 00000000..bd5f7883 --- /dev/null +++ b/source/plugins/introduction/queries/user.graphql @@ -0,0 +1,5 @@ +query IntroductionUser { + user(login: "$login") { + bio + } +} \ No newline at end of file diff --git a/source/plugins/introduction/tests.yml b/source/plugins/introduction/tests.yml new file mode 100644 index 00000000..567c7158 --- /dev/null +++ b/source/plugins/introduction/tests.yml @@ -0,0 +1,12 @@ +- name: Introduction plugin (default) + uses: lowlighter/metrics@latest + with: + token: MOCKED_TOKEN + plugin_introduction: yes + +- name: Introduction plugin (complete) + uses: lowlighter/metrics@latest + with: + token: MOCKED_TOKEN + plugin_introduction: yes + plugin_introduction_title: no \ No newline at end of file diff --git a/source/templates/classic/partials/_.json b/source/templates/classic/partials/_.json index 9671fd96..e4fa7d5c 100644 --- a/source/templates/classic/partials/_.json +++ b/source/templates/classic/partials/_.json @@ -1,5 +1,6 @@ [ "base.header", + "introduction", "base.activity+community", "base.repositories", "followup", diff --git a/source/templates/classic/partials/introduction.ejs b/source/templates/classic/partials/introduction.ejs new file mode 100644 index 00000000..b36f9650 --- /dev/null +++ b/source/templates/classic/partials/introduction.ejs @@ -0,0 +1,26 @@ +<% if (plugins.introduction) { %> +
+ <% if (plugins.introduction.title) { %> +

+ + About <%= {user:"me", organization:"us", repository:""}[plugins.introduction.mode] %> +

+ <% } %> +
> + <% if (plugins.introduction.error) { %> +
+
+ + <%= plugins.introduction.error.message %> +
+
+ <% } else { %> +
+
+ <%= plugins.introduction.text %> +
+
+ <% } %> +
+
+<% } %> \ No newline at end of file diff --git a/source/templates/classic/style.css b/source/templates/classic/style.css index ef480595..98e64b48 100644 --- a/source/templates/classic/style.css +++ b/source/templates/classic/style.css @@ -707,6 +707,12 @@ right: 100%; } +/* Introduction */ + .introduction { + white-space: normal; + margin: 0 13px 2px; + } + /* Fade animation */ .af { opacity: 0; diff --git a/source/templates/repository/partials/_.json b/source/templates/repository/partials/_.json index 9bc05974..89b92521 100644 --- a/source/templates/repository/partials/_.json +++ b/source/templates/repository/partials/_.json @@ -1,5 +1,6 @@ [ "base.header", + "introduction", "followup", "languages", "projects", diff --git a/source/templates/repository/partials/introduction.ejs b/source/templates/repository/partials/introduction.ejs new file mode 100644 index 00000000..b36f9650 --- /dev/null +++ b/source/templates/repository/partials/introduction.ejs @@ -0,0 +1,26 @@ +<% if (plugins.introduction) { %> +
+ <% if (plugins.introduction.title) { %> +

+ + About <%= {user:"me", organization:"us", repository:""}[plugins.introduction.mode] %> +

+ <% } %> +
> + <% if (plugins.introduction.error) { %> +
+
+ + <%= plugins.introduction.error.message %> +
+
+ <% } else { %> +
+
+ <%= plugins.introduction.text %> +
+
+ <% } %> +
+
+<% } %> \ No newline at end of file