[sysadmin-bin] Make sure description and homepage are kept up-to-date between DOAPs and GitHub



commit 6010c6aeab72402403fa31e3383ee4ba2cbc9d45
Author: Andrea Veri <averi redhat com>
Date:   Thu Jun 28 10:45:07 2018 +0200

    Make sure description and homepage are kept up-to-date between DOAPs and GitHub

 git/post-receive-mirror-github | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
---
diff --git a/git/post-receive-mirror-github b/git/post-receive-mirror-github
index 0f59970..66a05ce 100755
--- a/git/post-receive-mirror-github
+++ b/git/post-receive-mirror-github
@@ -85,6 +85,29 @@ class GitHub:
 
         raise Exception("There was an error attempting to create the repo %s in github:\n\nStatus: 
%d\nText:\n%s" % (name, rq.status_code, rq.text))
 
+    def update_github_repo(self, name, field, value):
+        payload = json.dumps({
+                             '%s' % field: value,
+                             })
+        rq = requests.patch('https://api.github.com/repos/'+ORGANIZATION+'/'+name,
+                             auth=(self.user, self.pw),
+                             data=payload)
+        if rq.status_code == 200:
+            return
+
+        raise Exception("There was an error attempting to update the repo %s in github:\n\nStatus: 
%d\nText:\n%s" % (name, rq.status_code, rq.text))
+
+    def fetch_github_repo(self, name):
+        rq = requests.get('https://api.github.com/repos/'+ORGANIZATION+'/'+name, auth=(self.user, self.pw))
+
+        description = rq.json()['description']
+        homepage = rq.json()['homepage']
+
+        if rq.status_code == 200:
+            return description, homepage
+
+        raise Exception("There was an error attempting to fetch the repo %s in github:\n\nStatus: 
%d\nText:\n%s" % (name, rq.status_code, rq.text))
+
     def normalize_name (self, name):
         if name in name_maps.keys():
             return name_maps[name]
@@ -134,8 +157,16 @@ def main ():
     gh = GitHub ()
     repo_name = get_repo_name ()
     github_name = gh.normalize_name (repo_name)
+    description, homepage = gh.fetch_github_repo(github_name)
+    settings = get_repo_settings (repo_name)
+
+    if description != settings["description"]:
+        gh.update_github_repo(github_name, 'description', description)
+
+    if homepage != settings["homepage"]:
+        gh.update_github_repo(github_name, 'homepage', homepage)
+
     if not gh.check_if_repo_exists(repo_name):
-        settings = get_repo_settings (repo_name)
         gh.create_github_repo (settings["name"], settings["description"], settings["homepage"])
     try:
         command = 'git push --mirror git github com:%s/%s' % (ORGANIZATION, github_name)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]