Merge pull request #4037 from thelounge/xpaw/rm-graphql-request

Remove `graphql-request` dependency from changelog script
This commit is contained in:
Pavel Djundik 2020-08-18 11:00:29 +03:00 committed by GitHub
commit c29ae50392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 43 deletions

View File

@ -88,7 +88,6 @@
"eslint-config-prettier": "6.11.0",
"eslint-plugin-vue": "6.2.2",
"fuzzy": "0.1.3",
"graphql-request": "1.8.2",
"husky": "4.2.5",
"mini-css-extract-plugin": "0.10.0",
"mocha": "8.1.1",

View File

@ -49,7 +49,7 @@ const _ = require("lodash");
const colors = require("chalk");
const fs = require("fs");
const path = require("path");
const GraphQLClient = require("graphql-request").GraphQLClient;
const got = require("got");
const dayjs = require("dayjs");
const semver = require("semver");
const util = require("util");
@ -236,19 +236,31 @@ function fullChangelogUrl(v1, v2) {
// This class is a facade to fetching details about commits / PRs / tags / etc.
// for a given repository of our organization.
class RepositoryFetcher {
// Holds a GraphQLClient and the name of the repository within the
// organization https://github.com/thelounge.
constructor(graphqlClient, repositoryName) {
this.graphqlClient = graphqlClient;
// Holds a Github token and repository name
constructor(githubToken, repositoryName) {
this.githubToken = githubToken;
this.repositoryName = repositoryName;
}
// Base function that actually makes the GraphQL API call
async fetch(query, variables = {}) {
return this.graphqlClient.request(
query,
Object.assign(variables, {repositoryName: this.repositoryName})
);
const response = await got
.post("https://api.github.com/graphql", {
json: {
query: query,
variables: Object.assign(variables, {repositoryName: this.repositoryName}),
},
headers: {
Authorization: `Bearer ${this.githubToken}`,
},
})
.json();
if (!response.errors && response.data) {
return response.data;
}
throw new Error(`GraphQL request returned no data: ${JSON.stringify(response)}`);
}
// Returns the git commit that is attached to a given tag
@ -789,12 +801,6 @@ function extractContributors(entries) {
return Array.from(set).sort((a, b) => a.localeCompare(b, "en", {sensitivity: "base"}));
}
const client = new GraphQLClient("https://api.github.com/graphql", {
headers: {
Authorization: `bearer ${token}`,
},
});
// Main function. Given a version string (i.e. not a tag!), returns a changelog
// entry and the list of contributors, for both pre-releases and stable
// releases. Templates are located at the top of this file.
@ -803,7 +809,7 @@ async function generateChangelogEntry(changelog, targetVersion) {
let template;
let contributors = [];
const codeRepo = new RepositoryFetcher(client, "thelounge");
const codeRepo = new RepositoryFetcher(token, "thelounge");
const previousVersion = await codeRepo.fetchPreviousVersion(targetVersion);
if (isPrerelease(targetVersion)) {
@ -817,7 +823,7 @@ async function generateChangelogEntry(changelog, targetVersion) {
items = parse(codeCommitsAndPullRequests);
items.milestone = await codeRepo.fetchMilestone(targetVersion);
const websiteRepo = new RepositoryFetcher(client, "thelounge.github.io");
const websiteRepo = new RepositoryFetcher(token, "thelounge.github.io");
const previousWebsiteVersion = await websiteRepo.fetchPreviousVersion(targetVersion);
const websiteCommitsAndPullRequests = await websiteRepo.fetchCommitsAndPullRequestsSince(
"v" + previousWebsiteVersion

View File

@ -2575,14 +2575,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7:
safe-buffer "^5.0.1"
sha.js "^2.4.8"
cross-fetch@2.2.2:
version "2.2.2"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-2.2.2.tgz#a47ff4f7fc712daba8f6a695a11c948440d45723"
integrity sha1-pH/09/xxLauo9qaVoRyUhEDUVyM=
dependencies:
node-fetch "2.1.2"
whatwg-fetch "2.0.4"
cross-spawn@^6.0.5:
version "6.0.5"
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4"
@ -4157,13 +4149,6 @@ grapheme-splitter@^1.0.4:
resolved "https://registry.yarnpkg.com/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz#9cf3a665c6247479896834af35cf1dbb4400767e"
integrity sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==
graphql-request@1.8.2:
version "1.8.2"
resolved "https://registry.yarnpkg.com/graphql-request/-/graphql-request-1.8.2.tgz#398d10ae15c585676741bde3fc01d5ca948f8fbe"
integrity sha512-dDX2M+VMsxXFCmUX0Vo0TopIZIX4ggzOtiCsThgtrKR4niiaagsGTDIHj3fsOMFETpa064vzovI+4YV4QnMbcg==
dependencies:
cross-fetch "2.2.2"
growl@1.10.5:
version "1.10.5"
resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e"
@ -5957,11 +5942,6 @@ node-addon-api@2.0.0:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.0.tgz#f9afb8d777a91525244b01775ea0ddbe1125483b"
integrity sha512-ASCL5U13as7HhOExbT6OlWJJUV/lLzL2voOSP1UVehpRD8FbSrSDjfScK/KwAvVTI5AS6r4VwbOMlIqtvRidnA==
node-fetch@2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.1.2.tgz#ab884e8e7e57e38a944753cec706f788d1768bb5"
integrity sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=
node-forge@0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.1.tgz#775368e6846558ab6676858a4d8c6e8d16c677b5"
@ -9695,11 +9675,6 @@ webpack@4.44.1:
watchpack "^1.7.4"
webpack-sources "^1.4.1"
whatwg-fetch@2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"
integrity sha512-dcQ1GWpOD/eEQ97k66aiEVpNnapVj90/+R+SXTPYGHpYBBypfKJEQjLrvMZ7YXbKm21gXd4NcuxUTjiv1YtLng==
which-module@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a"