Skip to content

Commit 2bd7dec

Browse files
authored
Merge pull request #90 from SAP/fixes
Fixes
2 parents 123f794 + 26e678c commit 2bd7dec

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

infrabox/utils/storage/docker-compose.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ services:
1010
ports:
1111
- "9009:9000"
1212

13-
minio-init:
14-
build:
15-
context: ../../../
16-
dockerfile: src/docker-compose/minio-init/Dockerfile
17-
links:
18-
- minio
19-
2013
postgres:
2114
build:
2215
context: ../../../

src/github/trigger/trigger.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ def create_job(self, commit_id, clone_url, build_id, project_id, github_private_
138138
'Create Jobs', %s, false, '', 1, 1024, %s, %s, null)
139139
''', [build_id, project_id, json.dumps(git_repo), env], fetch=False)
140140

141+
def has_active_build(self, commit_id, project_id):
142+
result = self.execute('''
143+
SELECT count(*)
144+
FROM job
145+
JOIN build ON job.build_id = build.id
146+
JOIN "commit" ON build.commit_id = "commit".id and build.project_id = commit.project_id
147+
WHERE "commit".id = %s AND commit.project_id = %s AND job.state IN ('running', 'queued', 'scheduled')
148+
GROUP BY job.state
149+
''', [commit_id, project_id])
150+
151+
if result:
152+
return True
153+
154+
return False
141155

142156
def create_push(self, c, repository, branch, tag):
143157
if not c['distinct']:
@@ -162,6 +176,9 @@ def create_push(self, c, repository, branch, tag):
162176

163177
commit_id = c['id']
164178

179+
if self.has_active_build(commit_id, project_id):
180+
return
181+
165182
if not result:
166183
status_url = repository['statuses_url'].format(sha=c['id'])
167184
result = self.execute('''
@@ -364,6 +381,10 @@ def handle_pull_request(self, event):
364381
return res(200, 'build already triggered')
365382

366383
commit_id = result[0][0]
384+
385+
if self.has_active_build(commit_id, project_id):
386+
return res(200, 'build already triggered')
387+
367388
build_id = self.create_build(commit_id, project_id)
368389
self.create_job(event['pull_request']['head']['sha'],
369390
event['pull_request']['head']['repo']['clone_url'],

0 commit comments

Comments
 (0)