[sysadmin-bin] Land a script that will allow us to keep gitlab.gnome.org/GNOME and github.com/GNOME in sync (https:
- From: Andrea Veri <averi src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Land a script that will allow us to keep gitlab.gnome.org/GNOME and github.com/GNOME in sync (https:
- Date: Thu, 7 Feb 2019 12:14:15 +0000 (UTC)
commit 8a0b480a638306e254293e63115f971c3d7a4010
Author: Andrea Veri <averi redhat com>
Date: Thu Feb 7 13:13:46 2019 +0100
Land a script that will allow us to keep gitlab.gnome.org/GNOME and github.com/GNOME in sync
(https://gitlab.gnome.org/Infrastructure/Infrastructure/issues/79)
deprecated_github_repos.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 91 insertions(+)
---
diff --git a/deprecated_github_repos.py b/deprecated_github_repos.py
new file mode 100755
index 0000000..d42bddd
--- /dev/null
+++ b/deprecated_github_repos.py
@@ -0,0 +1,91 @@
+#!/usr/bin/python
+
+import os
+
+cfg_file = '/home/admin/secret/github2.oauth'
+
+if not os.path.isfile(cfg_file):
+ print 'No configuration file could be found at %s' % cfg_file
+ sys.exit(1)
+else:
+ import ConfigParser
+
+ secure_config = ConfigParser.ConfigParser()
+ secure_config.read(cfg_file)
+
+if secure_config.has_option("github", "oauth_token"):
+ auth_token = secure_config.get("github", "oauth_token")
+else:
+ print 'Make sure %s has a github section and an oauth_token key/value pair' % cfg_file
+ sys.exit(1)
+
+def l_gitlab_repos():
+ import gitlab
+ gitlab_projects = list()
+
+ execfile('/home/admin/secret/gitlab_rw')
+ gl = gitlab.Gitlab('https://gitlab.gnome.org', GITLAB_PRIVATE_RW_TOKEN, api_version=4)
+
+ group = gl.groups.get(8, with_projects=False)
+ projects = group.projects.list(all=True)
+
+ for project in projects:
+ gitlab_projects.append(project.attributes['path'])
+
+ return gitlab_projects
+
+def l_github_repos(url='https://api.github.com/orgs/GNOME/repos?per_page=100'):
+ from urllib2 import urlopen, Request
+ import json
+
+ github_projects = list()
+ url = str(url)
+
+ req = Request(url)
+ req.add_header('Authorization', 'token %s' % auth_token)
+ response = urlopen(req)
+ link = response.info().getheader('link')
+ response.close()
+
+ links = link.split(' ')
+ last_page =
links[-2].replace('<','').replace('>','').replace(';','').split('?')[1].split('&')[1].split('=')[1]
+
+ for i in range(1, int(last_page) + 1):
+ _url = url + '&page=%i' % i
+ r = Request(_url)
+ r.add_header('Authorization', 'token %s' % auth_token)
+ resp = urlopen(r)
+
+ content = resp.read()
+ parsed_json = json.loads(content)
+ resp.close()
+
+ for repository in parsed_json:
+ repo_name = repository['name']
+
+ github_projects.append(repo_name)
+
+ return github_projects
+
+def delete_repo(repo_name, url='https://api.github.com/repos/GNOME'):
+ from urllib2 import urlopen, Request, HTTPError
+ import sys
+
+ url = str('%s/%s') % (url, repo_name)
+
+ req = Request(url)
+ req.add_header('Authorization', 'token %s' % auth_token)
+ req.get_method = lambda: 'DELETE'
+
+ try:
+ response = urlopen(req)
+ print '%s is being deleted' % repo_name
+ except HTTPError as e:
+ print 'Error processing %s: %i' % (repo_name, e.code)
+
+gitlab_repos = l_gitlab_repos()
+github_repos = l_github_repos()
+
+for repo in github_repos:
+ if repo not in gitlab_repos:
+ delete_repo(repo)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]