[sysadmin-bin] Get refs to push from local filesystem instead of remote APIs
- From: Bartłomiej Piotrowski <bpiotrowski src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Get refs to push from local filesystem instead of remote APIs
- Date: Tue, 15 Oct 2019 12:54:57 +0000 (UTC)
commit 18be18a101dfee1c1992c178fc29d29c52694c09
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date: Tue Oct 15 14:54:22 2019 +0200
Get refs to push from local filesystem instead of remote APIs
git/post-receive-mirror-github | 35 +++++++++++++++++++----------------
1 file changed, 19 insertions(+), 16 deletions(-)
---
diff --git a/git/post-receive-mirror-github b/git/post-receive-mirror-github
index 5e6956e..030cd45 100755
--- a/git/post-receive-mirror-github
+++ b/git/post-receive-mirror-github
@@ -40,7 +40,7 @@ from email.mime.text import MIMEText
import tempfile
import json
-from git import get_project_head_name
+from git import get_project_head_name, get_project_branches
ORGANIZATION="GNOME"
ADDITIONAL_ORGANIZATIONS={"pitivi": ["pitivi"]}
@@ -147,6 +147,7 @@ def get_repo_settings(repo_name):
# Get the repo's mainline branch name
branch_name = get_project_head_name()
+ branches = get_project_branches()
doap_url = 'https://gitlab.gnome.org/%s/%s/raw/%s/%s.doap' %
(os.path.dirname(os.getcwd()).split('/')[-1], repo_name, branch_name, repo_name)
@@ -172,6 +173,7 @@ def get_repo_settings(repo_name):
"name": repo_name.encode("utf-8").decode("utf-8"),
"description": desc.encode("utf-8").decode("utf-8"),
"default_branch": branch_name.encode("utf-8").decode("utf-8"),
+ "branches": branches,
}
@@ -186,9 +188,11 @@ def main():
settings = get_repo_settings(repo_name)
repo_exists = gh.check_if_repo_exists(repo_name)
+ # Avoid master here as we will later push it under different name
+ refs = ["refs/heads/{}".format(branch) for branch in settings['branches'] if branch != "master"]
+
if repo_exists:
description, homepage, default_branch, branches = gh.fetch_github_repo(github_name)
- refs = ["refs/heads/{}".format(branch) for branch in branches]
if description != settings["description"]:
gh.update_github_repo(github_name, 'description', settings["description"])
@@ -197,8 +201,7 @@ def main():
gh.update_github_repo(github_name, 'homepage', settings["homepage"])
else:
gh.create_github_repo(settings["name"], settings["description"], settings["homepage"])
- default_branch = ""
- refs = ""
+ default_branch = settings["default_branch"]
for organization in [gh.organization] + ADDITIONAL_ORGANIZATIONS.get(repo_name, []):
try:
@@ -221,18 +224,18 @@ def main():
# Drop master branch in separate loop as GitHub API disallows to drop the
# default branch and also expects new default branch to exists
for organization in [gh.organization] + ADDITIONAL_ORGANIZATIONS.get(repo_name, []):
- try:
- command = 'git push --force git github com:{}/{} :master'.format(organization, github_name)
- out = tempfile.NamedTemporaryFile(prefix="github",suffix="std")
- err = tempfile.NamedTemporaryFile(prefix="github",suffix="err")
- subprocess.check_call(shlex.split(command), stderr=err, stdout=out)
- out.close()
- err.close()
- except subprocess.CalledProcessError:
- out = open(out.name, "r")
- err = open(err.name, "r")
- raise Exception("Error trying to push repo %s/%s\nSTDOUT:\n%s\nSTDERR\n%s" % (organization,
repo_name, out.read(), err.read()))
-
+ if 'master' in branches:
+ try:
+ command = 'git push --force git github com:{}/{} :master'.format(organization, github_name)
+ out = tempfile.NamedTemporaryFile(prefix="github",suffix="std")
+ err = tempfile.NamedTemporaryFile(prefix="github",suffix="err")
+ subprocess.check_call(shlex.split(command), stderr=err, stdout=out)
+ out.close()
+ err.close()
+ except subprocess.CalledProcessError:
+ out = open(out.name, "r")
+ err = open(err.name, "r")
+ raise Exception("Error trying to push repo %s/%s\nSTDOUT:\n%s\nSTDERR\n%s" % (organization,
repo_name, out.read(), err.read()))
if __name__ == "__main__":
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]