woodpecker pull request

This commit is contained in:
unurled 2023-04-25 19:49:51 +02:00
parent 39de57bf69
commit ce3d1ac697
7 changed files with 652 additions and 43 deletions

3
scripts/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
node_modules/
main.js
package-lock.json

47
scripts/git_release.py Normal file
View file

@ -0,0 +1,47 @@
import os
import argparse
import giteapy
from giteapy.rest import ApiException
parser = argparse.ArgumentParser(description="publish to git.unurled.me the release.")
parser.add_argument('--token', type=str, help="a token which have sufficient permission")
parser.add_argument('--message', type=str)
parser.add_argument('--prerelease', type=bool)
parser.add_argument('--tag', type=str)
args = parser.parse_args()
doc = vars(args)
print(doc)
configuration = giteapy.Configuration()
configuration.api_key['access_token'] = doc['token']
configuration.host = 'https://git.unurled.me/api/v1'
api_instance = giteapy.RepositoryApi(giteapy.ApiClient(configuration))
owner = "Elixium"
repo = "Raxen"
body = giteapy.CreateReleaseOption(body=doc['message'], draft=False, name=doc['tag'], prerelease=doc['prerelease'], tag_name=doc['tag'], target_commitish="string")
attachments = []
for file in os.listdir(os.getcwd() +"../build/libs"):
if file.endswith('.jar'):
if file.startswith('raxen'):
attachments.append(os.getcwd() + '../build/libs/' + file)
print(attachments)
attachment1 = attachments[0]
attachment2 = attachments[1]
attachment3 = attachments[2]
name1 = attachments[0].split("libs/")[1]
name2 = attachments[1].split("libs/")[1]
name3 = attachments[2].split("libs/")[1]
try:
# Create a release
api_response = api_instance.repo_create_release(owner, repo, body=body)
print(api_response.id)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment1, name=name1)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment2, name=name2)
attachement_response = api_instance.repo_create_release_attachment(owner, repo, api_response.id, attachment=attachment3, name=name3)
print(attachement_response)
except ApiException as e:
print("Exception when calling RepositoryApi->repo_create_release: %s\n" % e)

56
scripts/main.ts Normal file
View file

@ -0,0 +1,56 @@
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));

20
scripts/package.json Normal file
View file

@ -0,0 +1,20 @@
{
"name": "scripts",
"version": "1.0.0",
"description": "a script for pull request comment",
"main": "main.js",
"author": "unurled",
"license": "MIT",
"scripts": {
"build": "tsc",
"start": "node main.js"
},
"dependencies": {
"cross-fetch": "^3.1.5",
"gitea-js": "^1.19.1"
},
"devDependencies": {
"@types/node": "^18.16.0",
"typescript": "^5.0.4"
}
}

8
scripts/tsconfig.json Normal file
View file

@ -0,0 +1,8 @@
{
"compilerOptions": {
"module": "CommonJS"
},
"files": [
"main.ts"
]
}