Skip to content

Commit

Permalink
Update create_merge_request.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
liorj-orca authored Mar 3, 2024
1 parent f08fe1b commit 89d0907
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions .github/workflows/create_merge_request.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
#!/bin/bash
echo test test
# GitHub repository details

# GitLab repository details
REPO=$1
BRANCH=$2
TITLE=$3
BODY=$4

# Generate a random string for the branch name
RANDOM_BRANCH=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)

# Create a new branch
git checkout -b $RANDOM_BRANCH
# Clone the repository
git clone "https://gitlab.com/$REPO" temp_repo
cd temp_repo

# Make changes to the repository
# For demonstration purposes, echo some content to a file
echo "Changes" >> changes.txt
# For demonstration purposes, let's edit an existing file
echo "Changes" >> existing_file.txt

# Add and commit changes
git add .
git add existing_file.txt
git commit -m "Automated changes"

# Push the branch to GitHub
# Generate a random string for the branch name
RANDOM_BRANCH=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)

# Create a new branch
git checkout -b $RANDOM_BRANCH

# Push the branch to GitLab
git push origin $RANDOM_BRANCH

# Create a pull request
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-d '{ "title": "'"$TITLE"'", "body": "'"$BODY"'", "head": "'"$RANDOM_BRANCH"'", "base": "'"$BRANCH"'" }' \
"https://api.github.com/repos/$REPO/pulls"
# Create a merge request
curl --request POST \
--header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"source_branch": "'"$RANDOM_BRANCH"'",
"target_branch": "'"$BRANCH"'",
"title": "'"$TITLE"'",
"description": "'"$BODY"'"
}' \
"https://gitlab.com/api/v4/projects/$REPO/merge_requests"

# Cleanup: Remove temporary cloned repository
cd ..
rm -rf temp_repo

0 comments on commit 89d0907

Please sign in to comment.