---
title: "Wrapping up the Pull Request from terminal"
slug: wrapping-up-the-pull-request-from-terminal
section: tech
date: 2015-10-24T10:07:00.000Z
canonical: https://roland.leth.ro/blog/tech/wrapping-up-the-pull-request-from-terminal
---

You might want to read the [the first part](/tech/blog/opening-pull-requests-from-terminal) and [the second part](/tech/blog/improving-the-pull-request-from-terminal), too.

During the weekend I rewrote a lot of the script, covering cases where the Pull Request failed, adding [Fastlane](https://fastlane.tools) automation and all around improvements.

The script has now 2 possible parameters, a different branch than `development`, and `skip_deploy`, in case we don't want to auto-run the fastlane command. Comments explaining the flow, as usual:

```bash
perform_pull_request() {
  # Default to not skipping deploy.
  skip_deploy=false
  sd="sd"
  # Default to development branch as base.
  branch="development"
  branch_to_push="$(parse_git_branch)"

  yellow "Pushing $branch_to_push to remote..."
  git push origin "$branch_to_push":"$branch_to_push"

  # If the first or second parameter is "sd",
  # we are going to skip running fastlane.
  if [ "$1" == "$sd" ] || [ "$2" == "$sd" ]; then
    skip_deploy=true
  fi

  if [ $? -eq 0 ]; then
    green "Push to remote successful."
  fi

  # If the first or second parameter is not empty *and* it's different than "sd",
  # it means we asked for a new branch as base.
  if [ -n "$1" ] && [ "$1" != "$sd" ]; then
    branch=$1
  elif [ -n "$2" ] && [ "$2" != "$sd" ]; then
    branch=$1
  fi

  yellow "Creating Pull Request to $branch: \"$(formatted_git_branch)\"..."
  pr_url=$(hub pull-request -b "$branch" -m "$(formatted_git_branch)")

  if [ $? -eq 0 ]; then
    # If we didn't run the fastlane command, it usually means we just want
    # to merge it, so let's open the GitHub page.
    if [ $skip_deploy == true ]; then
      open "$pr_url"
    else
      # If we did run the fastlane command, it usually means
      # the build is going to Hockey for QA to test, but
      # why not copy the Pull Request URL, just in case?
      green "Pull Request opened at ${yellow}$(echo $pr_url | pbcopy)$(pbpaste), ${green}and its URL was copied to your clipboard."
    fi
  elif [ $? -eq 1 ]; then
    red "Something went wrong, opening GitHub's Pull Requests page..."
    open "https://github.com/[...]/pulls"
  fi

  if [ $skip_deploy == false ]; then
    yellow "Handing over to Fastlane now..."
    fastlane hockey scheme:debug
  fi
}
```

Also, the Alfred workflow changed slightly, to compensate for these changes:

```bash
cd ~/path/to/project && gitpr {query}
```

I'm pretty sure I could improve this a lot, but it's the first `bash` script I have a go at, so if you have any suggestions, please let me know [@roland.leth.ro](https://bsky.app/profile/roland.leth.ro).
