Skip to content

Commit 4bc4203

Browse files
committed
merge_remote Makefile target
1 parent 265bfdc commit 4bc4203

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

Makefile

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,24 @@ blank_examples:clean_examples
205205
cd docs; julia notebooks_to_md.jl
206206

207207
# @devs
208-
branch_master: error_missing_repos_var
209-
# GitHub merge of `branch` into `master` for a series of repos
210-
# >> make branch_master branch=my_branch repos='FUSE IMAS IMASdd'
211-
@$(foreach repo,$(repos), \
212-
curl -X POST \
213-
-H "Authorization: token $$(security find-generic-password -a orso82 -s GITHUB_TOKEN -w)" \
214-
-H "Accept: application/vnd.github.v3+json" \
215-
https://api.github.com/repos/ProjectTorreyPines/$(repo).jl/merges \
216-
-d '{"base": "master", "head": "$(branch)", "commit_message": "merging $(branch) into master"}';)
208+
merge_remote: error_missing_repo_var error_missing_branch_var
209+
# GitHub merge of `branch` into master for a given `repo`
210+
# >> make merge_remote branch=my_branch repo=FUSE
211+
@merge_response=$$(curl -s -o /dev/null -w "%{http_code}" -X POST \
212+
-H "Authorization: token $$(security find-generic-password -a orso82 -s GITHUB_TOKEN -w)" \
213+
-H "Accept: application/vnd.github.v3+json" \
214+
https://api.github.com/repos/ProjectTorreyPines/$(repo).jl/merges \
215+
-d '{"base": "master", "head": "$(branch)", "commit_message": "merging $(branch) into master"}'); \
216+
echo "Merge response code: $$merge_response"; \
217+
if [ "$$merge_response" -eq 201 ]; then \
218+
echo "Merge successful. Deleting branch $(branch) from remote..."; \
219+
curl -X DELETE \
220+
-H "Authorization: token $$(security find-generic-password -a orso82 -s GITHUB_TOKEN -w)" \
221+
-H "Accept: application/vnd.github.v3+json" \
222+
https://api.github.com/repos/ProjectTorreyPines/$(repo).jl/git/refs/heads/$(branch); \
223+
else \
224+
echo "Merge failed with status code $$merge_response. Branch $(branch) was not deleted."; \
225+
fi
217226

218227
# @devs
219228
bump_major: error_missing_repo_var error_on_last_commit_is_a_version_bump versions_used
@@ -496,10 +505,10 @@ ifeq ($(repo),)
496505
endif
497506

498507
# @devs
499-
error_missing_repos_var:
500-
# Throw an error if environment variable `repos` is not set
501-
ifeq ($(repo),)
502-
$(error `repos` variable is not set)
508+
error_missing_branch_var:
509+
# Throw an error if environment variable `branch` is not set
510+
ifeq ($(branch),)
511+
$(error `branch` variable is not set)
503512
endif
504513

505514
# @devs

0 commit comments

Comments
 (0)