def repo_version(): version = StringIO() try: git.describe("--tags", "--exact-match", _out=version) except sh.ErrorReturnCode_128: git.log(pretty="format:%h", n=1, _out=version) return version.getvalue().strip()
def print_git_log(log_cmd: str) -> None: log = git.log( # type:ignore ["--oneline", "--graph", log_cmd], _timeout=constants.GIT_SH_TIMEOUT).stdout rr = cast(bytes, log).decode("utf-8").rstrip().split("\n") r = "\n| ".join(rr) click.echo("| " + r, err=True)
def __call__(self, params): # Destination file name. params = params[0] repetition = params["repetition"] del params["repetition"] fname = job_file_name(self.basedir, self.exp_name, repetition, **params) if os.path.exists(fname): print("Already run: {}".format(fname)) return # This process name. setproctitle(f"eli: {fname}") # Log git commit if git repo. try: git_commit = git.log().split()[1] except: git_commit = "no-git-repo" if self.automatic_seed: # TODO: set seeds from other libraries too. np.random.seed(repetition) dt_started = str(arrow.utcnow()) # Run. try: print(f"Running: {fname}") res = self.func(**params) print(f"Finished: {fname}") except Exception as e: print("Failed: {}".format(fname)) print(e) return # Store results. if res is None: return results = {} results["name"] = os.path.basename(os.path.dirname(fname)) results["results"] = res results["parameters"] = params results["repetition"] = repetition results["git-commit"] = git_commit results["started"] = dt_started results["finished"] = str(arrow.utcnow()) if not os.path.exists(os.path.dirname(fname)): os.makedirs(os.path.dirname(fname)) with open(fname, "w") as f: json.dump(results, f, indent=4)
def get_contributors(repo, commit_range): output = StringIO() try: git.log("--pretty=tformat:%H,%ae,%ce", commit_range, _out=output) except sh.ErrorReturnCode_128: print("Skipping contributors for:", repo) pass output = output.getvalue().strip() contributors = {} if not output: return contributors for log_line in output.split("\n"): sha, author_email, committer_email = log_line.split(",") author = redis.get("github_username:"******"github_username:"******"/repos/" + repo + "/commits/" + sha) github_commit_info = github_commit_info.json() if github_commit_info["author"]: author = github_commit_info["author"]["login"] redis.set("github_username:"******"committer"]: committer = github_commit_info["committer"]["login"] redis.set("github_username:"******"utf-8") committer = committer.decode("utf-8") if committer_email == "*****@*****.**": committer = None if author and author not in contributors: contributors[author] = 0 if committer and committer not in contributors: contributors[committer] = 0 if author: contributors[author] += 1 if committer and committer != author: contributors[committer] += 1 return contributors
if len(sys.argv) != 5: print( f'Usage: {sys.argv[0]} [starting commit/tag] [ending commit/tag] [GitHub username] [GitHub password]' ) sys.exit(1) from_commit = sys.argv[1] to_commit = sys.argv[2] username = sys.argv[3] password = sys.argv[4] contributors = set() reviewers = set() for line in git.log(f'{from_commit}..{to_commit}', '--pretty=format:%s', '--reverse'): m = re.search('\(#([0-9]+)\)$', line.rstrip()) if m: pr_id = m.group(1) print(f'PR #{pr_id}') r = requests.get( f'https://api.github.com/repos/dmlc/xgboost/pulls/{pr_id}/commits', auth=(username, password)) assert r.status_code == requests.codes.ok, f'Code: {r.status_code}, Text: {r.text}' commit_list = json.loads(r.text) try: contributors.update( [commit['author']['login'] for commit in commit_list]) except TypeError: contributors.update(
def repo_sha(): version = StringIO() git.log(pretty="format:%H", n=1, _out=version) return version.getvalue().strip()
def print_git_log(log_cmd: str) -> None: log = git.log(["--oneline", "--graph", log_cmd]).stdout # type:ignore rr = cast(bytes, log).decode("utf-8").rstrip().split("\n") r = "\n| ".join(rr) click.echo("| " + r, err=True)
import requests import json if len(sys.argv) != 5: print(f'Usage: {sys.argv[0]} [starting commit/tag] [ending commit/tag] [GitHub username] [GitHub password]') sys.exit(1) from_commit = sys.argv[1] to_commit = sys.argv[2] username = sys.argv[3] password = sys.argv[4] contributors = set() reviewers = set() for line in git.log(f'{from_commit}..{to_commit}', '--pretty=format:%s', '--reverse'): m = re.search('\(#([0-9]+)\)', line.rstrip()) if m: pr_id = m.group(1) print(f'PR #{pr_id}') r = requests.get(f'https://api.github.com/repos/dmlc/xgboost/pulls/{pr_id}/commits', auth=(username, password)) assert r.status_code == requests.codes.ok, f'Code: {r.status_code}, Text: {r.text}' commit_list = json.loads(r.text) try: contributors.update([commit['author']['login'] for commit in commit_list]) except TypeError: contributors.update(str(input(f'Error fetching contributors for PR #{pr_id}. Enter it manually, as a space-separated list:')).split(' ')) r = requests.get(f'https://api.github.com/repos/dmlc/xgboost/pulls/{pr_id}/reviews', auth=(username, password)) assert r.status_code == requests.codes.ok, f'Code: {r.status_code}, Text: {r.text}'
################################### SCRIPT ################################### ############################################################################## # Set directory of git repo git = git.bake(_cwd=UNITY_REPO_DIR) # TODO: Make sure to pull from git repo and ensure it's up-to-date and on # the correct branch # Initialize empty dictionary & keys neat_commits = {key: [] for key in VALID_CATEGORIES + ["Misc"]} # Acquire the latest commit that's been included in the patch notes latest_commit = get_previous_head_commit() git_log_output = git.log("--pretty=oneline", "--abbrev-commit", f"{latest_commit}..HEAD") # Cancel if there are no new commits if not git_log_output: write_log("No new commits. Cancelling patch notes generation") exit(0) # Populate dictionary to handoff to page generator for line in git_log_output: line = line.rstrip("\n") # remove trailing newline new_commit = generate_commit(line) # generate commit object if new_commit is not None: neat_commits[new_commit.category].append(new_commit) # Get current date to label patch notes date_tag = date.today().strftime(DATE_FORMAT)
app.config['MAIL_PASSWORD'] = "******" mail = Mail(app) login_manager = LoginManager(app) bootstrap = Bootstrap(app) moment = Moment(app) db = SQLAlchemy(app) login_manager.session_protection = "strong" timelimit = 1 NOT_START_STRING = "活动尚未开始。" NOT_ACTIVATE_STRING = "对不起,你的账户还未激活!" FEMALE = 0 MALE = 1 GIT_DATA = git.log('-1', '--pretty=%H%n%an%n%s').strip().split("\n") def checkTimeLimit(): # 返回1则正在活动 nowtime = datetime.now() starttime = datetime(2019, 3, 1, 20, 0, 0, 0) endtime = datetime(2019, 3, 14, 0, 0, 0, 0) return starttime <= nowtime < endtime # 格式化邮件 def mySendMailFormat(mailSubject, mailSender, mailRecv, mailBody, templates, **kwargs): msg = Message(mailSubject, sender=mailSender, recipients=[mailRecv]) msg.body = render_template(templates + ".txt", **kwargs)