diff --git a/.github/workflows/create_merge_request.sh b/.github/workflows/create_merge_request.sh index 53a1b55..d77bebb 100644 --- a/.github/workflows/create_merge_request.sh +++ b/.github/workflows/create_merge_request.sh @@ -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