@changesets/get-github-info
Advanced tools
Comparing version 0.4.3 to 0.4.4
# @changesets/get-github-info | ||
## 0.4.4 | ||
### Patch Changes | ||
- [`f24f722`](https://github.com/atlassian/changesets/commit/f24f7220fcc322a4a2deb26cd77c2d481ac422f0) [#444](https://github.com/atlassian/changesets/pull/444) Thanks [@Andarist](https://github.com/Andarist)! - Changed the way how requests to the GitHub API were authenticated - from a query parameter to the `Authorization` header. The previously used method has been deprecated by the GitHub and will stop working in 2021. | ||
## 0.4.3 | ||
@@ -4,0 +10,0 @@ |
@@ -1,5 +0,6 @@ | ||
export declare function getInfo(request: { | ||
declare type RequestData = { | ||
commit: string; | ||
repo: string; | ||
}): Promise<{ | ||
}; | ||
export declare function getInfo(request: RequestData): Promise<{ | ||
user: string | null; | ||
@@ -13,1 +14,2 @@ pull: number | null; | ||
}>; | ||
export {}; |
@@ -70,4 +70,7 @@ 'use strict'; | ||
}); | ||
const data = await fetch(`https://api.github.com/graphql?access_token=${process.env.GITHUB_TOKEN}`, { | ||
const data = await fetch("https://api.github.com/graphql", { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Token ${process.env.GITHUB_TOKEN}` | ||
}, | ||
body: JSON.stringify({ | ||
@@ -74,0 +77,0 @@ query: makeQuery(repos) |
@@ -23,4 +23,7 @@ "use strict"; | ||
}); | ||
const data = await fetch(`https://api.github.com/graphql?access_token=${process.env.GITHUB_TOKEN}`, { | ||
const data = await fetch("https://api.github.com/graphql", { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Token ${process.env.GITHUB_TOKEN}` | ||
}, | ||
body: JSON.stringify({ | ||
@@ -27,0 +30,0 @@ query: makeQuery(repos) |
@@ -64,4 +64,7 @@ import fetch from 'node-fetch'; | ||
}); | ||
const data = await fetch(`https://api.github.com/graphql?access_token=${process.env.GITHUB_TOKEN}`, { | ||
const data = await fetch("https://api.github.com/graphql", { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Token ${process.env.GITHUB_TOKEN}` | ||
}, | ||
body: JSON.stringify({ | ||
@@ -68,0 +71,0 @@ query: makeQuery(repos) |
{ | ||
"name": "@changesets/get-github-info", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"description": "Get the GitHub username and PR number from a commit. Intended for use with changesets.", | ||
@@ -15,4 +15,4 @@ "main": "dist/get-github-info.cjs.js", | ||
"nock": "^11.7.0", | ||
"prettier": "^1.18.2" | ||
"prettier": "^1.19.1" | ||
} | ||
} |
@@ -7,6 +7,10 @@ import { getInfo } from "."; | ||
let apiPath = `/graphql?access_token=${process.env.GITHUB_TOKEN}`; | ||
let apiPath = `/graphql`; | ||
test("associated with multiple PRs with only one merged", async () => { | ||
nock("https://api.github.com") | ||
nock("https://api.github.com", { | ||
reqheaders: { | ||
Authorization: `Token ${process.env.GITHUB_TOKEN}` | ||
} | ||
}) | ||
.post(apiPath, ({ query }) => { | ||
@@ -118,3 +122,7 @@ expect(prettier.format(query, { parser: "graphql" })) | ||
test("associated with multiple PRs with multiple merged gets the one that was merged first", async () => { | ||
nock("https://api.github.com") | ||
nock("https://api.github.com", { | ||
reqheaders: { | ||
Authorization: `Token ${process.env.GITHUB_TOKEN}` | ||
} | ||
}) | ||
.post(apiPath, ({ query }) => { | ||
@@ -226,3 +234,7 @@ expect(prettier.format(query, { parser: "graphql" })) | ||
test("gets the author of the associated pull request if it exists rather than the author of the changeset", async () => { | ||
nock("https://api.github.com") | ||
nock("https://api.github.com", { | ||
reqheaders: { | ||
Authorization: `Token ${process.env.GITHUB_TOKEN}` | ||
} | ||
}) | ||
.post(apiPath, ({ query }) => { | ||
@@ -229,0 +241,0 @@ expect(prettier.format(query, { parser: "graphql" })) |
@@ -5,2 +5,7 @@ // @ts-ignore | ||
type RequestData = { | ||
commit: string; | ||
repo: string; | ||
}; | ||
function makeQuery(repos: any) { | ||
@@ -61,3 +66,3 @@ return ` | ||
// so instead of doing a bunch of network requests, we can do a single one. | ||
const GHDataLoader = new DataLoader(async (requests: any[]) => { | ||
const GHDataLoader = new DataLoader(async (requests: RequestData[]) => { | ||
if (!process.env.GITHUB_TOKEN) { | ||
@@ -68,3 +73,3 @@ throw new Error( | ||
} | ||
let repos: Record<any, any> = {}; | ||
let repos: Record<RequestData["repo"], Array<RequestData["commit"]>> = {}; | ||
requests.forEach(({ commit, repo }) => { | ||
@@ -77,9 +82,9 @@ if (repos[repo] === undefined) { | ||
const data = await fetch( | ||
`https://api.github.com/graphql?access_token=${process.env.GITHUB_TOKEN}`, | ||
{ | ||
method: "POST", | ||
body: JSON.stringify({ query: makeQuery(repos) }) | ||
} | ||
).then((x: any) => x.json()); | ||
const data = await fetch("https://api.github.com/graphql", { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Token ${process.env.GITHUB_TOKEN}` | ||
}, | ||
body: JSON.stringify({ query: makeQuery(repos) }) | ||
}).then((x: any) => x.json()); | ||
@@ -108,6 +113,5 @@ // this is mainly for the case where there's an authentication problem | ||
export async function getInfo(request: { | ||
commit: string; | ||
repo: string; | ||
}): Promise<{ | ||
export async function getInfo( | ||
request: RequestData | ||
): Promise<{ | ||
user: string | null; | ||
@@ -114,0 +118,0 @@ pull: number | null; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
33948
781