diff --git a/src/main.ts b/src/main.ts index e46ec7c..bd759cc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -31,8 +31,8 @@ import {ChatGpt} from "./chat-gpt"; import {Feedback} from "./feedback"; import {Titled} from "./titled"; import {Excluded} from "./excluded"; -import {Ranged} from "./ranged"; -import {Blob} from "./blob"; +import {Puzzled} from "./puzzled"; +import {Pdd} from "./pdd"; export let github: { context: { @@ -99,21 +99,9 @@ async function run() { core.setFailed(reason); throw new Error(reason); } - // if (new Puzzled(body).value()) { - // // run pdd.ts - // } - // const puzzle = new Ranged( - // await new Blob(octokit).asText(), - // "150-156" - // ).asText(); - // console.log(puzzle); - - const puzzle = new Ranged( - await new Blob(octokit).asText(), - "150-156" - ).asText(); - console.log(puzzle); - + if (new Puzzled(body).value()) { + await new Pdd(octokit).run(); + } const openai = core.getInput("openai_token"); if (openai) { const model = core.getInput("openai_model"); diff --git a/src/pdd.ts b/src/pdd.ts new file mode 100644 index 0000000..3bf81da --- /dev/null +++ b/src/pdd.ts @@ -0,0 +1,52 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Tracehub.git + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import {Ranged} from "./ranged"; +import {Blob} from "./blob"; +import {Octokit} from "@octokit/rest"; + +/** + * PDD routine. + */ +export class Pdd { + + /** + * Ctor. + * @param github GitHub + */ + constructor(private readonly github: Octokit) { + } + + /** + * Run it. + */ + async run() { + const puzzle = new Ranged( + await new Blob(this.github).asText(), // async -> await + "150-156" // from parsed link + // /https://github.com/tracehubpm/tracehub/blob/8d2aca048e33a5c9d83a49af4246c9ad7fde9998/src/main/java/git/tracehub/tk/TkGitHub.java#L150-L156 + ).asText(); + console.log(puzzle); + } +} diff --git a/src/puzzled.ts b/src/puzzled.ts new file mode 100644 index 0000000..54db591 --- /dev/null +++ b/src/puzzled.ts @@ -0,0 +1,45 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2023-2024 Tracehub.git + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/** + * Puzzled or not. + */ +export class Puzzled { + + /** + * Ctor. + * @param report Bug report + */ + constructor(private readonly report: string) { + } + + /** + * Is it puzzled or not. + */ + value(): boolean { + return new RegExp( + "The puzzle `*.+` from #\d+ has to be resolved*.+" + ).test(this.report); + } +}