import { giteaApi, CreatePullReviewOptions } from 'gitea-js'; import fetch from 'cross-fetch'; // You have to use a fetch compatible polyfill like cross-fetch for Node.JS import fs = require('fs'); import path = require('path'); const api = giteaApi('https://git.unurled.me', { token: process.env.TOKEN, customFetch: fetch, }); const todo: { [file: string]: string[]} = {}; function searchTodo(file: string): void { let compteur = 0; const lines: string[] = fs.readFileSync(file, 'utf-8').split('\n'); for (const line of lines) { compteur += 1; if (line.match(/[\S\s]*\btodo\b/i)) { if (file in todo) { todo[file].push(line.trim() + " (line " + compteur + ")"); } else { todo[file] = [line.trim() + " (line " + compteur + ")"]; } } } } function searchTodoInDir(dir: string): void { fs.readdirSync(dir).forEach(file => { const filePath = path.join(dir, file); if (fs.statSync(filePath).isDirectory()) { searchTodoInDir(filePath); } if (file.endsWith(".java")) { searchTodo(filePath); } }); } function searchTodoInProject(): void { const pwd = path.dirname(path.dirname(path.resolve(__filename))); searchTodoInDir(path.join(pwd, "src/main/java/me/unurled/raxen")); } searchTodoInProject(); console.log(); const index: number = Number.parseInt(process.env.CI_COMMIT_PULL_REQUEST); const body: CreatePullReviewOptions = { body: "# TODO that needs to be done by next big release :\n```json\n" + JSON.stringify(todo, null, "\t") + "\n```", commit_id: process.env.CI_COMMIT_SHA, }; const pr_review = api.repos.repoCreatePullReview(process.env.CI_REPO_OWNER, process.env.CI_REPO_NAME, index, body, {}); pr_review.then(res => console.log(res)).catch(err => console.log(err));