Skip to content

Commit 5bdbe41

Browse files
authored
Merge pull request #133 from ruby-no-kai/generate_sponsors_yaml_file_job_reuse2
GitHubPusher: add commits instead of resetting branch
2 parents ad18d61 + d34ebaa commit 5bdbe41

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

app/jobs/generate_sponsors_yaml_file_job.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,26 +169,23 @@ def push
169169
return
170170
end
171171

172-
reset_branch
172+
ensure_branch
173173
commit_content
174174
create_or_update_pull_request
175175
end
176176

177177
private
178178

179-
def reset_branch
180-
begin
181-
octokit.delete_branch(@repo.name, @branch_name)
182-
rescue Octokit::UnprocessableEntity
183-
end
184-
185-
head = octokit.branch(@repo.name, base_branch)
186-
octokit.create_ref(@repo.name, "refs/heads/#{@branch_name}", head[:commit][:sha])
179+
def ensure_branch
180+
octokit.branch(@repo.name, @branch_name)
181+
rescue Octokit::NotFound
182+
head_sha = octokit.branch(@repo.name, base_branch)[:commit][:sha]
183+
octokit.create_ref(@repo.name, "refs/heads/#{@branch_name}", head_sha)
187184
end
188185

189186
def commit_content
190187
begin
191-
blob_sha = octokit.contents(@repo.name, path: @filepath, ref: base_branch)[:sha]
188+
blob_sha = octokit.contents(@repo.name, path: @filepath, ref: @branch_name)[:sha]
192189
rescue Octokit::NotFound
193190
blob_sha = nil
194191
end

0 commit comments

Comments
 (0)