Skip to content

Commit 02f9bc7

Browse files
committed
Enable to specify branch by PR parameter.
1 parent e52deb9 commit 02f9bc7

4 files changed

Lines changed: 23 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.0.4] - 2021-01-13
10+
911
### Added
1012

1113
* Enable to specify branch by "#" in REPO
1214
* e.g. REPO="https://github.com/user/mt-plugin-XXX.git#main"
15+
* Enable to specify branch by PR parameter
16+
* e.g. PR="https://github.com/movabletype/movabletype/pull/1527"
1317

1418
## [1.0.3] - 2020-10-22
1519

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,17 @@ ifneq (${ARCHIVE},)
9696
${MAKEFILE_DIR}/bin/extract-archive ${BASE_ARCHIVE_PATH} ${MT_HOME_PATH} $(shell echo ${ARCHIVE} | tr ',' ' ')
9797
endif
9898

99-
$(eval export _ARGS=$(shell UPDATE_BRANCH=${UPDATE_BRANCH} ${MAKEFILE_DIR}/bin/setup-environment --recipe "$(shell echo ${RECIPE} | tr ',' ' ')" --repo "$(shell echo ${REPO} | tr ',' ' ')"))
99+
$(eval export _ARGS=$(shell UPDATE_BRANCH=${UPDATE_BRANCH} ${MAKEFILE_DIR}/bin/setup-environment --recipe "$(shell echo ${RECIPE} | tr ',' ' ')" --repo "$(shell echo ${REPO} | tr ',' ' ')" --pr "$(shell echo ${PR} | tr ',' ' ')"))
100100
ifneq (${RECIPE},)
101101
@perl -e 'exit(length($$ENV{_ARGS}) > 0 ? 0 : 1)'
102102
endif
103103
ifneq (${REPO},)
104104
@perl -e 'exit(length($$ENV{_ARGS}) > 0 ? 0 : 1)'
105105
endif
106-
${MAKE} up-common-invoke-docker-compose MT_HOME_PATH=${MT_HOME_PATH} ${_ARGS} RECIPE="" REPO="" $(shell [ -n "${DOCKER_MT_IMAGE}" ] && echo "DOCKER_MT_IMAGE=${DOCKER_MT_IMAGE}") $(shell [ -n "${DOCKER_MYSQL_IMAGE}" ] && echo "DOCKER_MYSQL_IMAGE=${DOCKER_MYSQL_IMAGE}")
106+
ifneq (${PR},)
107+
@perl -e 'exit(length($$ENV{_ARGS}) > 0 ? 0 : 1)'
108+
endif
109+
${MAKE} up-common-invoke-docker-compose MT_HOME_PATH=${MT_HOME_PATH} ${_ARGS} RECIPE="" REPO="" PR="" $(shell [ -n "${DOCKER_MT_IMAGE}" ] && echo "DOCKER_MT_IMAGE=${DOCKER_MT_IMAGE}") $(shell [ -n "${DOCKER_MYSQL_IMAGE}" ] && echo "DOCKER_MYSQL_IMAGE=${DOCKER_MYSQL_IMAGE}")
107110

108111
up-common-invoke-docker-compose: setup-mysql-volume
109112
@echo MT_HOME_PATH=${MT_HOME_PATH}

bin/git-clone

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ git fetch --tags --prune
1616
if [ "$UPDATE_BRANCH" = "yes" -o "$UPDATE_BRANCH" = "1" ] && [ -n "$branch" ]; then
1717
git checkout .
1818
git clean -f
19+
20+
if [[ $branch == pull/* ]]; then
21+
git fetch origin refs/$branch:refs/remotes/origin/$branch
22+
fi
1923
git checkout $branch
24+
2025
if git symbolic-ref --short HEAD 2>/dev/null; then
2126
git rebase $(git rev-parse --abbrev-ref --symbolic-full-name @{u})
2227
fi

bin/setup-environment

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use File::Temp qw(tempfile tmpnam);
2020
GetOptions(
2121
'recipe=s' => \my $recipes,
2222
'repo=s' => \my $repos,
23+
'pr=s' => \my $pull_reqs,
2324
);
2425

2526
my $recipe_dir = realpath("$FindBin::Bin/../recipe");
@@ -61,8 +62,14 @@ sub handle_recipe {
6162
}
6263

6364
if ($repo) {
64-
my $cmd
65-
= "$git_clone_cmd $repo $dest_dir @{[$data->{$k}{branch} || '']}";
65+
my $branch = $data->{$k}{branch} || '';
66+
for my $pr ( split /\s+/, $pull_reqs ) {
67+
my ($pr_repo, $pr_id) = ($pr =~ m{([^/]+)/(pull/\d+)});
68+
next unless $pr_repo && $pr_id;
69+
$branch = $pr_id . '/head' if basename($dest_dir) eq $pr_repo;
70+
}
71+
72+
my $cmd = "$git_clone_cmd $repo $dest_dir $branch";
6673
my $res = `$cmd 2>&1` || "";
6774
die "$res\nGot an error: $cmd" if $?;
6875

0 commit comments

Comments
 (0)