supression module auto-pr
This commit is contained in:
parent
233c85d8b6
commit
348f1f1aa2
@ -1,44 +0,0 @@
|
||||
{lib, config, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.auto-pr;
|
||||
in
|
||||
{
|
||||
options.services.auto-pr = {
|
||||
enable = mkEnableOption "Cron job PR mise à jour automatique";
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
|
||||
systemd.services.auto-pr-bot = {
|
||||
description = "Création d'un PR si mise à jour";
|
||||
requires = ["network-online.target"];
|
||||
environment = { HOME = "/var/lib/auto-pr-bot"; };
|
||||
serviceConfig = {
|
||||
DynamicUser = true;
|
||||
CacheDirectory = "auto-pr-bot";
|
||||
StateDirectory = "auto-pr-bot";
|
||||
Type = "oneshot";
|
||||
ExecStart = with pkgs;
|
||||
let env = python3Packages.python.buildEnv.override {
|
||||
extraLibs = [ python3Packages.PyGithub python3Packages.pyjwt python3Packages.colorama ];
|
||||
ignoreCollisions = true;
|
||||
};
|
||||
in "${pkgs.writeShellScriptBin "run.sh" ''
|
||||
${env}/bin/python ${pkgs.writeScript "pr-autobot.py" "${readFile ./pr-autobot.py}"} --private-key /var/lib/auto-pr-bot/private-key.pem --app-id 19565 --installation-id 407088 --repo nyanloutre/nixpkgs --cache-dir /var/cache/auto-pr-bot --version 19.09
|
||||
''}/bin/run.sh";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.auto-pr-bot = {
|
||||
description = "Timer auto PR bot";
|
||||
requires = ["network-online.target"];
|
||||
wantedBy = ["multi-user.target"];
|
||||
timerConfig = { OnCalendar = "daily"; Unit = "auto-pr-bot.service"; };
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import jwt, time, urllib.request, json, datetime, argparse, sys, textwrap
|
||||
from github import Github
|
||||
from colorama import Fore, Style
|
||||
from time import sleep
|
||||
|
||||
parser = argparse.ArgumentParser(description='Create PR to update nixpkgs fork')
|
||||
parser.add_argument('--private-key')
|
||||
parser.add_argument('--app-id')
|
||||
parser.add_argument('--installation-id')
|
||||
parser.add_argument('--repo')
|
||||
parser.add_argument('--cache-dir')
|
||||
parser.add_argument('--version')
|
||||
args = vars(parser.parse_args())
|
||||
|
||||
channel_req = urllib.request.Request(url='https://nixos.org/channels/nixos-' + args["version"] + '/git-revision')
|
||||
latest_commit = urllib.request.urlopen(channel_req).read().decode('utf-8')
|
||||
try:
|
||||
previous_commit = open(args['cache_dir'] + '/git-revision', 'r').read()
|
||||
except FileNotFoundError:
|
||||
open(args['cache_dir'] + '/git-revision', 'w').write(latest_commit)
|
||||
print("Premier lancement, le hash du dernier commit à été sauvegardé")
|
||||
sys.exit(0)
|
||||
|
||||
print("Dernier commit : " + latest_commit)
|
||||
print("Commit précédent : " + previous_commit)
|
||||
|
||||
if latest_commit != previous_commit:
|
||||
bearer_token = jwt.encode({
|
||||
'iat': int(time.time()),
|
||||
'exp': int(time.time()) + (10 * 60),
|
||||
'iss': args['app_id']
|
||||
},
|
||||
open(args['private_key'],"r").read(),
|
||||
algorithm='RS256')
|
||||
|
||||
req = urllib.request.Request(url='https://api.github.com/app/installations/' +
|
||||
args['installation_id'] +
|
||||
'/access_tokens',
|
||||
method='POST')
|
||||
|
||||
req.add_header('Authorization', 'Bearer ' + bearer_token.decode('utf-8'))
|
||||
req.add_header('Accept', 'application/vnd.github.machine-man-preview+json')
|
||||
|
||||
token = json.loads(urllib.request.urlopen(req).read().decode('utf-8'))['token']
|
||||
|
||||
g = Github(token)
|
||||
repo = g.get_repo(args['repo'])
|
||||
|
||||
branch = "upgrade-" + datetime.datetime.now().strftime('%Y-%m-%d') + '-' + latest_commit[:11];
|
||||
|
||||
repo.create_git_ref('refs/heads/' + branch, latest_commit)
|
||||
|
||||
pr_message = textwrap.dedent("""\
|
||||
### Pull request automatique
|
||||
### Avancement mise à jour
|
||||
- [ ] Fusionner la branche
|
||||
""")
|
||||
|
||||
pr = repo.create_pull(title=branch, body=pr_message, base='nixos-' + args["version"], head=branch)
|
||||
|
||||
print("Pull request numéro " + str(pr.number) + " créée")
|
||||
print("URL : " + pr.html_url)
|
||||
|
||||
while pr.mergeable == None:
|
||||
pr = repo.get_pull(pr.number)
|
||||
sleep(1)
|
||||
|
||||
pr.edit(body = pr.body + "\n- [ ] Exécuter `nixos-rebuild -I nixpkgs=https://github.com/nyanloutre/nixpkgs/archive/" + pr.merge_commit_sha + ".tar.gz switch`")
|
||||
print("État : " + ((Fore.GREEN + "Fusionnable") if pr.mergeable else (Fore.RED + "Conflit")) + Style.RESET_ALL)
|
||||
|
||||
open(args['cache_dir'] + '/git-revision', 'w').write(latest_commit)
|
||||
else:
|
||||
print(Fore.GREEN + "Aucun changement détecté" + Style.RESET_ALL)
|
@ -25,7 +25,6 @@ in
|
||||
{
|
||||
imports = [
|
||||
../../services/mail-server.nix
|
||||
../../services/auto-pr.nix
|
||||
../../services/python-ci.nix
|
||||
../../services/sdtdserver.nix
|
||||
../../containers/vsftpd.nix
|
||||
@ -201,8 +200,6 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
auto-pr.enable = true;
|
||||
|
||||
sdtdserver.enable = false;
|
||||
|
||||
factorio = {
|
||||
|
Loading…
Reference in New Issue
Block a user