Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow commits to open PRs from gitlab #5108

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions .gitlab/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,35 @@ validate_version() {
fi
}

get_pr_count() {
local branch="$1"
local repo_url="$2"

pr_count="$( gh pr list --repo "$repo_url" --head "$branch" --state open --json id --jq length )"
if [[ ! "$pr_count" =~ ^[0-9]+$ ]]; then
echo "ERROR: Failed to get PRs for the $branch branch!" >&2
echo "$pr_count" >&2
exit 1
fi

echo "$pr_count"
}

setup_branch() {
local branch="$1"
local repo_url="$2"
local check_for_pr="${3:-true}"

# check if the branch exists
if git ls-remote --exit-code --heads origin "$branch"; then
# get number of open PRs for the branch
pr_count="$( gh pr list --repo "$repo_url" --head "$branch" --state open --json id --jq length )"
if [[ ! "$pr_count" =~ ^[0-9]+$ ]]; then
echo "ERROR: Failed to get PRs for the $branch branch!" >&2
echo "$pr_count" >&2
exit 1
fi
if [[ "$pr_count" != "0" ]]; then
echo ">>> The $branch branch exists and has $pr_count open PR(s)."
echo ">>> Nothing to do."
exit 0
if [ "$check_for_pr" = "true" ]; then
# get number of open PRs for the branch
pr_count="$( get_pr_count "$branch" "$repo_url" )"
if [[ "$pr_count" != "0" ]]; then
echo ">>> The $branch branch exists and has $pr_count open PR(s)."
echo ">>> Nothing to do."
exit 0
fi
fi
echo ">>> Resetting the $branch branch to main ..."
git checkout "$branch"
Expand Down
25 changes: 16 additions & 9 deletions .gitlab/update-otel-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ create_collector_pr() {
local repo="signalfx/splunk-otel-collector"
local repo_url="https://srv-gh-o11y-gdi:${GITHUB_TOKEN}@github.com/${repo}.git"
local message="Update OpenTelemetry Dependencies to $OTEL_VERSION"
local check_for_pr="true"
if [ "$OTEL_VERSION" = "main" ]; then
check_for_pr="false"
fi

echo ">>> Cloning the $repo repository ..."
git clone "$repo_url" collector-mirror
cd collector-mirror

setup_branch "$BRANCH" "$repo_url"
setup_branch "$BRANCH" "$repo_url" "$check_for_pr"

echo ">>> Updating otel deps to $OTEL_VERSION ..."
OTEL_VERSION="$OTEL_VERSION" ./internal/buildscripts/update-deps
Expand All @@ -32,14 +36,17 @@ create_collector_pr() {
if ! git diff --exit-code >/dev/null 2>&1; then
git commit -S -am "$message"
git push -f "$repo_url" "$BRANCH"
echo ">>> Creating the PR ..."
gh pr create \
--draft \
--repo "$repo" \
--title "$message" \
--body "$message" \
--base main \
--head "$BRANCH"
pr_count="$( get_pr_count "$BRANCH" "$repo_url" )"
if [ "$pr_count" = "0" ]; then
echo ">>> Creating the PR ..."
gh pr create \
--draft \
--repo "$repo" \
--title "$message" \
--body "$message" \
--base main \
--head "$BRANCH"
fi
fi
}

Expand Down
Loading