File: github_comment_bench.py

package info (click to toggle)
py7zr 0.22.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,300 kB
  • sloc: python: 8,740; makefile: 197; ansic: 35
file content (34 lines) | stat: -rw-r--r-- 1,236 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import argparse
import os
import pathlib

import github
import bench_result as bench


class CommentBenchmark:

    def __init__(self):
        parser = argparse.ArgumentParser(prog='bench_comment_issue')
        parser.add_argument('jsonfile', type=pathlib.Path, help='pytest-benchmark saved result')
        parser.add_argument('repository', help='Repository to post comment')
        parser.add_argument('issue_number', type=int, help='Issue number to post comment')
        parser.add_argument('run_id', help='Run ID of github actions')
        args = parser.parse_args()
        self.jsonfile = args.jsonfile
        self.repository = args.repository
        self.issue_number = args.issue_number
        self.run_id = args.run_id

    def post_comment(self):
        body = bench.generate_comment(self.jsonfile, type='github')
        body += '\n   Posted from [the action](https://github.com/{}/actions/runs/{})\n'.format(self.repository, self.run_id)
        token = os.getenv("GITHUB_TOKEN")
        g = github.Github(token)
        repo = g.get_repo(self.repository)
        issue = repo.get_issue(number=self.issue_number)
        issue.create_comment(body)


if __name__ == "__main__":
    CommentBenchmark().post_comment()