Skip to content

Commit 87d4e15

Browse files
committed
Should fix biotools maybe
1 parent cf66fce commit 87d4e15

File tree

1 file changed

+35
-44
lines changed

1 file changed

+35
-44
lines changed

github-ci/src/biocontainersci/biotools.py

Lines changed: 35 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@
55

66
import shutil
77
import requests
8-
import sys
98
import os
109
import logging
11-
import re
1210
import git
1311
import datetime
1412
from copy import deepcopy
15-
from yaml import load, dump
13+
from yaml import dump
1614
try:
17-
from yaml import CLoader as Loader, CDumper as Dumper
15+
from yaml import CDumper as Dumper
1816
except ImportError:
19-
from yaml import Loader, Dumper
17+
from yaml import Dumper
2018

2119
from biocontainersci.utils import BiocontainersCIException
2220

21+
2322
class Biotools:
2423

2524
GIT_REPO = '[email protected]:bio-tools/content.git'
@@ -90,15 +89,15 @@ def create_pr(self, branch):
9089
}
9190
github_url = 'https://api.github.com/repos/%s/pulls' % ("bio-tools/content")
9291
res = requests.post(
93-
github_url,
94-
json={
95-
'title': "biocontainers-bot metadata import PR",
96-
'head': branch,
97-
"base": "master"
98-
},
99-
headers=headers
92+
github_url,
93+
json={
94+
'title': "biocontainers-bot metadata import PR",
95+
'head': branch,
96+
"base": "master"
97+
},
98+
headers=headers
10099
)
101-
if not res.status_code in [200, 201]:
100+
if res.status_code not in [200, 201]:
102101
logging.error("[biotools] Failed to create pull request: %s", res.text)
103102
return False
104103
pr = res.json()
@@ -107,13 +106,13 @@ def create_pr(self, branch):
107106
github_url = 'https://api.github.com/repos/%s/issues/%d' % ("bio-tools/content", issue)
108107

109108
res = requests.post(
110-
github_url,
111-
json={
112-
'labels': [self.BOT_LABEL],
113-
},
114-
headers=headers
109+
github_url,
110+
json={
111+
'labels': [self.BOT_LABEL],
112+
},
113+
headers=headers
115114
)
116-
if not res.status_code in [200]:
115+
if res.status_code not in [200]:
117116
logging.error("Failed to add issue label: %d" % res.status_code)
118117

119118
logging.info("Tagged issue: %d" % issue)
@@ -173,37 +172,29 @@ def run(self, f, labels, branch=None):
173172

174173
for file_path in files_to_write:
175174

176-
if os.path.exists(file_path):
177-
with open(file_path) as fp:
178-
softwares = load(fp, Loader=Loader)
179-
180175
if name not in softwares["softwares"]:
181176
softwares["softwares"][name] = data
182177

183-
exists = False
184-
for download in softwares["softwares"][name]["versions"]:
185-
if download["version"] == container_version:
186-
exists = True
187-
break
178+
new_download = {
179+
"url": "biocontainers/" + name + ":" + container_version,
180+
"version": container_version,
181+
"type": "Container file",
182+
"labels": deepcopy(clabels)
183+
}
184+
softwares["softwares"][name]["versions"].append(new_download)
188185

189-
if not exists:
190-
new_download = {
191-
"url": "biocontainers/" + name + ":" + container_version,
192-
"version": container_version,
193-
"type": "Container file",
194-
"labels": deepcopy(clabels)
195-
}
196-
softwares["softwares"][name]["versions"].append(new_download)
197-
198-
with open(file_path, 'w') as fp:
199-
dump(softwares, fp, Dumper=Dumper)
186+
with open(file_path, 'w') as fp:
187+
dump(softwares, fp, Dumper=Dumper)
200188

189+
changed = False
190+
changed_files = [item.a_path for item in repo.index.diff(None)]
191+
for file_path in files_to_write:
192+
if file_path in changed_files:
201193
repo.index.add([file_path])
202-
if exists:
203-
if biotools is not None:
204-
repo.index.commit("Add version for %s:%s" % (biotools, container_version))
205-
else:
206-
repo.index.commit("Add version for %s:%s" % (name, container_version))
194+
changed = True
195+
196+
if changed:
197+
repo.index.commit("Add version for %s:%s" % (name, container_version))
207198
try:
208199
logging.info("[biotools] Push to branch %s" % branch)
209200

0 commit comments

Comments
 (0)