Skip to content

Commit 44e7a8a

Browse files
authored
Prevent the build running if the repo hasn't been created yet (#444)
## Status - Ready for review ## Points for consideration: - Security - Performance ## What's changed? FIxes a race condition where a build job is queued before the repo has been created
1 parent db97588 commit 44e7a8a

File tree

2 files changed

+6
-208
lines changed

2 files changed

+6
-208
lines changed

app/jobs/upload_job.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class UploadJob < ApplicationJob
3838
def perform(payload)
3939
modified_locales(payload).each do |locale|
4040
projects_data = load_projects_data(locale, repository(payload), owner(payload))
41+
if projects_data.data.repository.object.nil?
42+
Rails.logger.warn 'Build skipped, does the repo exist?'
43+
break
44+
end
45+
4146
projects_data.data.repository.object.entries.each do |project_dir|
4247
project = format_project(project_dir, locale, repository(payload), owner(payload))
4348
if @skip_job

lib/tasks/upload_task.rake

Lines changed: 1 addition & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -6,214 +6,7 @@ namespace :upload_job_test do
66
desc 'Test trigger the UploadJob'
77
task trigger: :environment do
88
# Paste in a payload from the GitHub webhook (https://github.com/organizations/raspberrypilearning/settings/hooks)
9-
payload = {
10-
ref: 'refs/heads/draft',
11-
before: '4c751b19488a0a6b4cbe4d86d27a63598b0dbf33',
12-
after: '477420b5822859d5b39b907f122ec51d227b2448',
13-
repository: {
14-
id: 860_323_001,
15-
node_id: 'R_kgDOM0d8uQ',
16-
name: 'test-project-dh',
17-
full_name: 'raspberrypilearning/test-project-dh',
18-
private: false,
19-
owner: {
20-
name: 'raspberrypilearning',
21-
email: nil,
22-
login: 'raspberrypilearning',
23-
id: 6_546_294,
24-
node_id: 'MDEyOk9yZ2FuaXphdGlvbjY1NDYyOTQ=',
25-
avatar_url: 'https://avatars.githubusercontent.com/u/6546294?v=4',
26-
gravatar_id: '',
27-
url: 'https://api.github.com/users/raspberrypilearning',
28-
html_url: 'https://github.com/raspberrypilearning',
29-
followers_url: 'https://api.github.com/users/raspberrypilearning/followers',
30-
following_url: 'https://api.github.com/users/raspberrypilearning/following{/other_user}',
31-
gists_url: 'https://api.github.com/users/raspberrypilearning/gists{/gist_id}',
32-
starred_url: 'https://api.github.com/users/raspberrypilearning/starred{/owner}{/repo}',
33-
subscriptions_url: 'https://api.github.com/users/raspberrypilearning/subscriptions',
34-
organizations_url: 'https://api.github.com/users/raspberrypilearning/orgs',
35-
repos_url: 'https://api.github.com/users/raspberrypilearning/repos',
36-
events_url: 'https://api.github.com/users/raspberrypilearning/events{/privacy}',
37-
received_events_url: 'https://api.github.com/users/raspberrypilearning/received_events',
38-
type: 'Organization',
39-
site_admin: false
40-
},
41-
html_url: 'https://github.com/raspberrypilearning/test-project-dh',
42-
description: nil,
43-
fork: false,
44-
url: 'https://github.com/raspberrypilearning/test-project-dh',
45-
forks_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/forks',
46-
keys_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/keys{/key_id}',
47-
collaborators_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/collaborators{/collaborator}',
48-
teams_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/teams',
49-
hooks_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/hooks',
50-
issue_events_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/issues/events{/number}',
51-
events_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/events',
52-
assignees_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/assignees{/user}',
53-
branches_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/branches{/branch}',
54-
tags_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/tags',
55-
blobs_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/git/blobs{/sha}',
56-
git_tags_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/git/tags{/sha}',
57-
git_refs_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/git/refs{/sha}',
58-
trees_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/git/trees{/sha}',
59-
statuses_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/statuses/{sha}',
60-
languages_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/languages',
61-
stargazers_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/stargazers',
62-
contributors_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/contributors',
63-
subscribers_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/subscribers',
64-
subscription_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/subscription',
65-
commits_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/commits{/sha}',
66-
git_commits_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/git/commits{/sha}',
67-
comments_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/comments{/number}',
68-
issue_comment_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/issues/comments{/number}',
69-
contents_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/contents/{+path}',
70-
compare_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/compare/{base}...{head}',
71-
merges_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/merges',
72-
archive_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/{archive_format}{/ref}',
73-
downloads_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/downloads',
74-
issues_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/issues{/number}',
75-
pulls_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/pulls{/number}',
76-
milestones_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/milestones{/number}',
77-
notifications_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/notifications{?since,all,participating}',
78-
labels_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/labels{/name}',
79-
releases_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/releases{/id}',
80-
deployments_url: 'https://api.github.com/repos/raspberrypilearning/test-project-dh/deployments',
81-
created_at: 1_726_820_154,
82-
updated_at: '2024-09-20T08:15:59Z',
83-
pushed_at: 1_726_838_069,
84-
git_url: 'git://github.com/raspberrypilearning/test-project-dh.git',
85-
ssh_url: '[email protected]:raspberrypilearning/test-project-dh.git',
86-
clone_url: 'https://github.com/raspberrypilearning/test-project-dh.git',
87-
svn_url: 'https://github.com/raspberrypilearning/test-project-dh',
88-
homepage: nil,
89-
size: 93,
90-
stargazers_count: 0,
91-
watchers_count: 0,
92-
language: nil,
93-
has_issues: true,
94-
has_projects: true,
95-
has_downloads: true,
96-
has_wiki: true,
97-
has_pages: false,
98-
has_discussions: false,
99-
forks_count: 0,
100-
mirror_url: nil,
101-
archived: false,
102-
disabled: false,
103-
open_issues_count: 0,
104-
license: {
105-
key: 'other',
106-
name: 'Other',
107-
spdx_id: 'NOASSERTION',
108-
url: nil,
109-
node_id: 'MDc6TGljZW5zZTA='
110-
},
111-
allow_forking: true,
112-
is_template: false,
113-
web_commit_signoff_required: false,
114-
topics: [],
115-
visibility: 'public',
116-
forks: 0,
117-
open_issues: 0,
118-
watchers: 0,
119-
default_branch: 'master',
120-
stargazers: 0,
121-
master_branch: 'master',
122-
organization: 'raspberrypilearning',
123-
custom_properties: {}
124-
},
125-
pusher: {
126-
name: 'danhalson',
127-
128-
},
129-
organization: {
130-
login: 'raspberrypilearning',
131-
id: 6_546_294,
132-
node_id: 'MDEyOk9yZ2FuaXphdGlvbjY1NDYyOTQ=',
133-
url: 'https://api.github.com/orgs/raspberrypilearning',
134-
repos_url: 'https://api.github.com/orgs/raspberrypilearning/repos',
135-
events_url: 'https://api.github.com/orgs/raspberrypilearning/events',
136-
hooks_url: 'https://api.github.com/orgs/raspberrypilearning/hooks',
137-
issues_url: 'https://api.github.com/orgs/raspberrypilearning/issues',
138-
members_url: 'https://api.github.com/orgs/raspberrypilearning/members{/member}',
139-
public_members_url: 'https://api.github.com/orgs/raspberrypilearning/public_members{/member}',
140-
avatar_url: 'https://avatars.githubusercontent.com/u/6546294?v=4',
141-
description: 'Learning Resources and Projects provided by the Raspberry Pi Foundation'
142-
},
143-
sender: {
144-
login: 'danhalson',
145-
id: 2_422_897,
146-
node_id: 'MDQ6VXNlcjI0MjI4OTc=',
147-
avatar_url: 'https://avatars.githubusercontent.com/u/2422897?v=4',
148-
gravatar_id: '',
149-
url: 'https://api.github.com/users/danhalson',
150-
html_url: 'https://github.com/danhalson',
151-
followers_url: 'https://api.github.com/users/danhalson/followers',
152-
following_url: 'https://api.github.com/users/danhalson/following{/other_user}',
153-
gists_url: 'https://api.github.com/users/danhalson/gists{/gist_id}',
154-
starred_url: 'https://api.github.com/users/danhalson/starred{/owner}{/repo}',
155-
subscriptions_url: 'https://api.github.com/users/danhalson/subscriptions',
156-
organizations_url: 'https://api.github.com/users/danhalson/orgs',
157-
repos_url: 'https://api.github.com/users/danhalson/repos',
158-
events_url: 'https://api.github.com/users/danhalson/events{/privacy}',
159-
received_events_url: 'https://api.github.com/users/danhalson/received_events',
160-
type: 'User',
161-
site_admin: false
162-
},
163-
created: false,
164-
deleted: false,
165-
forced: false,
166-
base_ref: nil,
167-
compare: 'https://github.com/raspberrypilearning/test-project-dh/compare/4c751b19488a...477420b58228',
168-
commits: [
169-
{
170-
id: '477420b5822859d5b39b907f122ec51d227b2448',
171-
tree_id: 'decae51495ca1df2ce4ec322fbc5ff1bcd768528',
172-
distinct: true,
173-
message: 'Create test.py',
174-
timestamp: '2024-09-20T14:14:29+01:00',
175-
url: 'https://github.com/raspberrypilearning/test-project-dh/commit/477420b5822859d5b39b907f122ec51d227b2448',
176-
author: {
177-
name: 'Dan Halson',
178-
179-
username: 'danhalson'
180-
},
181-
committer: {
182-
name: 'GitHub',
183-
184-
username: 'web-flow'
185-
},
186-
added: [
187-
'en/code/test.py'
188-
],
189-
removed: [],
190-
modified: []
191-
}
192-
],
193-
head_commit: {
194-
id: '477420b5822859d5b39b907f122ec51d227b2448',
195-
tree_id: 'decae51495ca1df2ce4ec322fbc5ff1bcd768528',
196-
distinct: true,
197-
message: 'Create test.py',
198-
timestamp: '2024-09-20T14:14:29+01:00',
199-
url: 'https://github.com/raspberrypilearning/test-project-dh/commit/477420b5822859d5b39b907f122ec51d227b2448',
200-
author: {
201-
name: 'Dan Halson',
202-
203-
username: 'danhalson'
204-
},
205-
committer: {
206-
name: 'GitHub',
207-
208-
username: 'web-flow'
209-
},
210-
added: [
211-
'en/code/test.py'
212-
],
213-
removed: [],
214-
modified: []
215-
}
216-
}
9+
payload = {}
21710

21811
abort('Stopping as no payload was provided (expects a payload from the GitHub webhook: https://github.com/organizations/raspberrypilearning/settings/hooks)') if payload.blank?
21912

0 commit comments

Comments
 (0)