-
Notifications
You must be signed in to change notification settings - Fork 19
modernize #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
modernize #120
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4639f8d
replace jest with node test runner
Uzlopak 4355886
modernize workflows
Uzlopak 8da2be6
replace standard with neostandard
Uzlopak a80e1dd
upgrade nock to 15
Uzlopak 2b44c70
convolut
Uzlopak 94cc956
build types dynamically
Uzlopak 164789d
fix linting
Uzlopak 503ff31
Potential fix for code scanning alert no. 6: Prototype-polluting assi…
Uzlopak a8fb7ab
dont need belt and suspenders
Uzlopak 158ceb7
actually, belt and suspenders
Uzlopak a8d5f46
belt and suspenders
Uzlopak ae17c3c
proper type generation
Uzlopak c374eeb
fix
Uzlopak d4515cd
Apply suggestion from @wolfy1339
Uzlopak 3311fab
Apply suggestion from @wolfy1339
Uzlopak c4739f3
Change require to import syntax in README
wolfy1339 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import neostandard from 'neostandard' | ||
|
|
||
| export default neostandard({}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,16 @@ | ||
| import { Context } from "probot"; | ||
|
|
||
| type StringOrNumber = number | string; | ||
| type Key = | ||
| | { [key: string]: StringOrNumber } | ||
| | StringOrNumber[] | ||
| | StringOrNumber; | ||
| type Value = Key; | ||
|
|
||
| declare function metadata( | ||
| context: Context, | ||
| issue?: { body: string; [key: string]: any } | ||
| ): { | ||
| get(key?: Key): Promise<any>; | ||
| set(key: Key, value: Value): Promise<any>; | ||
| export default metadata; | ||
| export type StringOrNumber = string | number; | ||
| export type Key = Record<string, StringOrNumber> | StringOrNumber | StringOrNumber[]; | ||
| export type Value = Key; | ||
| export type IssueOption = { | ||
| owner: string; | ||
| repo: string; | ||
| issue_number: number; | ||
| body?: string; | ||
| }; | ||
|
|
||
| export = metadata; | ||
| export type ProbotMetadata = { | ||
| get: (key?: Key) => Promise<Value | undefined>; | ||
| set: (key?: Key, value?: Value) => Promise<void>; | ||
| }; | ||
| export type ProbotMetadataConstructor = (context: import("probot").Context<"issue_comment">, issue?: IssueOption) => ProbotMetadata; | ||
| export const metadata: ProbotMetadataConstructor; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,89 @@ | ||
| const regex = /(\n\n|\r\n)<!-- probot = (.*) -->/ | ||
| const probotMetadataRegex = /(?:\n\n|\r\n)<!-- probot = (.*) -->/ | ||
| const prototypePollutionKeys = /** @type {const} */(['__proto__', 'constructor', 'prototype']) | ||
|
|
||
| module.exports = (context, issue = null) => { | ||
| const github = context.octokit || context.github | ||
| const prefix = context.payload.installation.id | ||
| const metadata = /** @type {ProbotMetadataConstructor} */ (context, issue) => { | ||
| const octokit = context.octokit | ||
| const prefix = /** @type {{ id: number; node_id: string; }} */ (context.payload.installation).id | ||
|
|
||
| if (!issue) issue = context.issue() | ||
|
|
||
| return { | ||
| async get (key = null) { | ||
| async get (key) { | ||
| let body = issue.body | ||
|
|
||
| if (!body) { | ||
| body = (await github.issues.get(issue)).data.body || '' | ||
| body = (await octokit.rest.issues.get(issue)).data.body || '' | ||
| } | ||
|
|
||
| const match = body.match(regex) | ||
| const match = body.match(probotMetadataRegex) | ||
|
|
||
| if (match) { | ||
| const data = JSON.parse(match[2])[prefix] | ||
| return key ? data && data[key] : data | ||
| const probotMetadata = JSON.parse(match[1]) | ||
| const data = probotMetadata[prefix] | ||
| return typeof key === 'string' || typeof key === 'number' | ||
| ? data && data[key] | ||
| : data | ||
| } | ||
| }, | ||
|
|
||
| async set (key, value) { | ||
| let body = issue.body | ||
| let data = {} | ||
| /** @type {Record<number, Record<number|string, any>>} */ | ||
| let data = Object.create(null) | ||
|
|
||
| if (!body) body = (await github.issues.get(issue)).data.body || '' | ||
| if (!body) body = (await octokit.rest.issues.get(issue)).data.body || '' | ||
|
|
||
| const match = body.match(regex) | ||
| const match = body.match(probotMetadataRegex) | ||
|
|
||
| if (match) { | ||
| data = JSON.parse(match[2]) | ||
| data = JSON.parse(match[1]) | ||
| } | ||
|
|
||
| body = body.replace(regex, '') | ||
| body = body.replace(probotMetadataRegex, '') | ||
|
|
||
| if (!data[prefix]) data[prefix] = {} | ||
| if (!data[prefix]) data[prefix] = Object.create(null) | ||
|
|
||
| if (typeof key === 'object') { | ||
| Object.assign(data[prefix], key) | ||
| } else { | ||
| // should never happen, but just in case | ||
| if (typeof prefix === 'string' && prototypePollutionKeys.includes(prefix)) { | ||
| throw new TypeError('Invalid prefix value') | ||
| } | ||
| if (typeof key === 'string' || typeof key === 'number') { | ||
| data[prefix][key] = value | ||
| } else { | ||
| Object.assign(data[prefix], key) | ||
| } | ||
|
|
||
| body = `${body}\n\n<!-- probot = ${JSON.stringify(data)} -->` | ||
| await octokit.rest.issues.update({ | ||
| owner: issue.owner, | ||
| repo: issue.repo, | ||
| issue_number: issue.issue_number, | ||
| body: `${body}\n\n<!-- probot = ${JSON.stringify(data)} -->` | ||
| }) | ||
|
|
||
| const { owner, repo, issue_number } = issue | ||
| return github.issues.update({ owner, repo, issue_number, body }) | ||
| issue.body = `${body}\n\n<!-- probot = ${JSON.stringify(data)} -->` | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export default metadata | ||
| export { metadata } | ||
|
|
||
| /** @typedef {string|number} StringOrNumber */ | ||
| /** @typedef {Record<string, StringOrNumber>|StringOrNumber|StringOrNumber[]} Key */ | ||
| /** @typedef {Key} Value */ | ||
|
|
||
| /** | ||
| * @typedef {object} IssueOption | ||
| * @property {string} owner | ||
| * @property {string} repo | ||
| * @property {number} issue_number | ||
| * @property {string} [body] | ||
| */ | ||
|
|
||
| /** | ||
| * @typedef {object} ProbotMetadata | ||
| * @property {(key?: Key)=>Promise<Value|undefined>} get | ||
| * @property {(key?: Key, value?: Value)=>Promise<void>} set | ||
| */ | ||
|
|
||
| /** @typedef {(context: import('probot').Context<'issue_comment'>, issue?: IssueOption)=>ProbotMetadata} ProbotMetadataConstructor */ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.