def add_changelog_template(token: str, patch_version: int, cwd: str) -> None:
    branch_name = changelog_branch_name(patch_version)
    git_command("checkout", "-b", branch_name, cwd=cwd)
    execute_command("python", "changelog.py", "--token", token, cwd=cwd)
    git_command("add", "_posts", cwd=cwd)
    git_command("commit", "-m", f"Changelog {patch_version}", cwd=cwd)
    git_command("push", "origin", branch_name, cwd=cwd)
Esempio n. 2
0
def git_info_refs(repo_name):
    repo_name = repo_name + '.git'

    repo_path = os.path.join(GIT_REPOS_PATH, repo_name)
    old_version = request.headers.get('Git-Protocol')
    version = request.headers.get('git/2.17.1')
    service = request.args.get('service')

    if service and 'git-' in service:
        service_name = service[4:]
    else:
        service_name = 'upload-pack'

    if service_name == 'receive-pack' and not auth.username():
        # push 操作需要验证
        return auth.login_required(git_info_refs)(repo_name)

    args = [service_name, "--stateless-rpc", "--advertise-refs", "."]

    res = git_command(repo_name, version, *args)

    first_line = '# service=git-%s\n0000' % service_name
    first_line = ('%.4x' % len(first_line)) + first_line

    resp = make_response(first_line + res.decode())
    resp.headers[
        'Content-Type'] = 'application/x-git-%s-advertisement' % service_name
    return resp
Esempio n. 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--token",
                        type=str,
                        required=True,
                        help="github token")

    args = parser.parse_args()

    repo = env("GITHUB_REPOSITORY")

    nightly_branch = get_branch(repo, args.token, NIGHTLY_BRANCH)
    if nightly_branch is not None:
        print("Repo already has nightly branch")
        return

    git_command("checkout", "-b", NIGHTLY_BRANCH)

    output = execute_command("rustc", "-V")
    match_result = RUSTC_VERSION_RE.match(output)
    date = match_result.group(1)
    with open(CHECK_WORKFLOW_PATH) as f:
        workflow_text = f.read()

    result = re.search(WORKFLOW_RUSTC_VERSION_RE, workflow_text)
    if result is None:
        raise ValueError("Failed to find the current version of nightly rust")

    new_workflow_text = re.sub(WORKFLOW_RUSTC_VERSION_RE,
                               f"\\g<1>{date}\\g<2>", workflow_text)
    if new_workflow_text == workflow_text:
        print("The latest nightly rustc version is already used")
        return

    with open(CHECK_WORKFLOW_PATH, "w") as f:
        f.write(new_workflow_text)

    if has_git_changes():
        git_command("add", CHECK_WORKFLOW_PATH)
        git_command("commit", "-m", ":arrow_up: nightly")

        git_command("push", "origin", NIGHTLY_BRANCH)
        pull_request = create_pull_request(repo, args.token, NIGHTLY_BRANCH,
                                           ":arrow_up: nightly")
        add_assignee(repo, args.token, pull_request["number"],
                     DEFAULT_ASSIGNEE)
    else:
        print("Everything is up to date")
Esempio n. 4
0
    def update(self) -> None:
        target_branch = get_branch(self.__repo, self.__token,
                                   self.__branch_name)
        if target_branch is not None:
            print(f"Repo already has `{self.__branch_name}` branch")
            return

        git_command("checkout", "-b", self.__branch_name)

        self._update_locally()

        if has_git_changes():
            git_command("commit", "-am", self.__message)

            git_command("push", "origin", self.__branch_name)
            pull_request = create_pull_request(self.__repo, self.__token,
                                               self.__branch_name,
                                               self.__message)
            add_assignee(self.__repo, self.__token, pull_request["number"],
                         self.__assignee)
        else:
            print("Everything is up-to-date")
from common import get_patch_version, inc_patch_version, GRADLE_PROPERTIES
from git import git_command

if __name__ == '__main__':
    patch_version = get_patch_version()

    release_branch = f"release-{patch_version}"
    git_command("branch", release_branch)
    git_command("push", "origin", release_branch)

    inc_patch_version()

    git_command("add", GRADLE_PROPERTIES)
    git_command("commit", "-m", ":arrow_up: patch version")
    git_command("push", "origin", "master")
Esempio n. 6
0
 def git(self, args):
   config = self.get_project_config()
   argv = args["argv"]
   for m in config["modules"]:
     git_command(self.root_dir, m, argv)
import re
from datetime import date

from common import get_patch_version
from git import git_command

PLUGIN_XML = "plugin/src/main/resources/META-INF/plugin.xml"

if __name__ == '__main__':
    with open(PLUGIN_XML) as f:
        text = f.read()
    today = date.today()
    version = get_patch_version() - 1
    new_text = re.sub(
        r"https://intellij-rust\.github\.io/.*\.html",
        f"https://intellij-rust.github.io/{today.year}/{today.month:02d}/{today.day:02d}/changelog-{version}.html",
        text)
    with (open(PLUGIN_XML, mode="w")) as f:
        f.write(new_text)

    git_command("add", PLUGIN_XML)
    git_command("commit", "-m", "Changelog")

    head = git_command("rev-parse", "HEAD")
    release_branch = f"release-{version}"
    git_command("checkout", release_branch)
    git_command("cherry-pick", head)

    git_command("push", "origin", "master")
    git_command("push", "origin", release_branch)
Esempio n. 8
0
import subprocess
from typing import List, Dict

from git import git_command

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--projects",
                        type=str,
                        help="Projects info in JSON format",
                        required=True)

    args = parser.parse_args()
    projects: List[Dict] = json.loads(args.projects)

    for project in projects:
        name = project["name"]
        path = f"testData/{name}"

        if name == "stdlib":
            subprocess.run([
                "cargo", "new", "--name", name, "--bin", "--vcs", "none", path
            ],
                           check=True,
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT)
        else:
            repository = project["repository"]
            git_command("clone", "--depth", "1",
                        f"https://github.com/{repository}.git", path)
Esempio n. 9
0
import argparse

from git import git_command

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--tag", type=str, help="tag name", required=True)
    parser.add_argument("--commit",
                        type=str,
                        help="commit hash",
                        required=True)

    args = parser.parse_args()

    git_command("tag", "-d", args.tag, check=False)
    git_command("tag", args.tag, args.commit)
    git_command("push", "-f", "origin", args.tag)
Esempio n. 10
0
 def git(root, config, args):
   argv = args["args"]
   for m in config["modules"]:
     git_command(root_dir, m, argv)
Esempio n. 11
0
import argparse
from subprocess import CalledProcessError

from git import git_command

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--tag", type=str, required=True, help="tag name")

    args = parser.parse_args()

    try:
        commit_hash = git_command("rev-list", "-n", "1", args.tag, print_stdout=False)
    except CalledProcessError:
        commit_hash = ""

    print(commit_hash)
Esempio n. 12
0
 def git(self, args):
     config = self.get_project_config()
     argv = args["argv"]
     for m in config["modules"]:
         git_command(self.root_dir, m, argv)
Esempio n. 13
0
 def git(root, config, args):
     argv = args["args"]
     for m in config["modules"]:
         git_command(root_dir, m, argv)