Skip to content

bash script to land a PR? #95

Closed
Closed

Description

@mcollina

I wrote this:

#! /bin/bash

set -x
set -e

curl -L https://github.com/nodejs/node/pull/$1.patch | git am --whitespace=fix
get-metadata $1 -f msg.txt
echo -e "$(git show -s --format=%B)\n\n$(cat msg.txt)" > msg.txt
git commit --amend -F msg.txt
git show -s --format=%B
./configure
make -j4 test

I think it might be something we might want to add here, in node, or mention it in the README

Activity

  1. joyeecheung commented on Nov 8, 2017

    @joyeecheung
    Member

    @mcollina I have a few custom git commands that are in essense using the same commands as the OP + some additional checking and configuration, I plan to open a PR later this week to see what people thinks. (If we point them to git-* bin targets of package.json, those will automatically appear as git commands).

    Here is a preview. I plan to make another one that handles the single-commit case so there will only be one command needed for the simplest cases. This allows user configure their upstream remote names and is aware of the branch that they are on.

    paste image

    (posted the wrong image earlier..)

  2. Tiriel commented on Nov 10, 2017

    @Tiriel
    Contributor

    Ref: #98

  3. self-assigned this
    on Nov 23, 2017
  4. BridgeAR commented on Dec 12, 2017

    @BridgeAR
    Member

    As I also use a very similar bash script at the moment - to handle multiple commits at a time I also added a conditional rebase

    COMMITS=$(git rev-list --count master...upstream/master)
    if [ $COMMITS != "1" ]
    then
      git rebase -i origin/master
    fi
  5. BridgeAR commented on Dec 12, 2017

    @BridgeAR
    Member

    I actually played a bit around and my script and it got a bit more sophisticated. Note - I use xclip to copy the message into the clipboard.
    UPDATE: Using multiple commits will now amend all commit messages properly.

    #!/bin/bash
    
    set -x
    set -e
    
    if [ $1 != "verify" ]
    then
    
      # Get the patch
      curl -L https://github.com/nodejs/node/pull/$1.patch | git am -3 --whitespace=fix
    
      # Run linter
      make lint
    
      # Check for more than one commit
      COMMITS=$(git rev-list --count master...origin/master)
    
      # Get metadata and add it to the commit message
      METADATA=$(get-metadata $1 -f)
      if [ $COMMITS != "1" ]
      then
        git rebase -i --autostash origin/master
        # Run linter again
        make lint
      fi
    
      # Update commits left
      COMMITS=$(git rev-list --count master...origin/master)
    
      NL=$'\n\n'
      # If there one commit add the commit message, else add the commit message for
      # each commit by using `--exec` with `git commit --amend`
      if [ $COMMITS = "1" ]
      then
        git commit --amend -m "$(git show -s --format=%B)$NL$METADATA"
      else
        echo -e "$NL$METADATA" > tmp_metadata.txt
        git rebase --autostash --quiet \
          --exec "git show -s --format=%B > tmp_message.txt" \
          --exec "cat tmp_metadata.txt >> tmp_message.txt" \
          --exec "git commit --amend -F tmp_message.txt" \
          --exec "rm tmp_message.txt"
        rm tmp_metadata.txt
      fi
    
    else
      COMMITS=$(git rev-list --count master...origin/master)
    fi
    
    # Validate all commit messages
    git rev-list master...origin/master | xargs core-validate-commit
    git log --format=%B -n $COMMITS
    
    # Copy the message for the PR to the clipboard
    if [ $COMMITS != "1" ] && [ $COMMITS != "2" ]
    then
      echo "Landed in $(git rev-parse origin/master) .. $(git rev-parse HEAD)" | xclip -sel clip
    else
      COMMIT_IDS=$(git log --format="%H" -n $COMMITS --reverse)
      echo "Landed in ${COMMIT_IDS//$'\n'/, }" | xclip -sel clip
    fi
  6. priyank-p commented on Dec 12, 2017

    @priyank-p
    Contributor

    Hey @BridgeAR xclip for copying data is a great idea but the problem is bash pr is till Work in Progress.

  7. BridgeAR commented on Dec 12, 2017

    @BridgeAR
    Member

    @cPhost I just thought I might share it as it does a few more things and if someone wants to use, they can. I am probably going to improve that a bit further from time to time.

  8. BridgeAR commented on Jan 12, 2018

    @BridgeAR
    Member

    The current version of my script does quite a lot automated already. It will e.g. rebase nicely and stuff like that. In the end it copies a message for the users in the clipboard in a nice way as well.

  9. BridgeAR commented on Jan 12, 2018

    @BridgeAR
    Member

    Note: I have a "weird" setup so most people would have to switch origin/master to upstream/master.

  10. joyeecheung commented on Jan 17, 2018

    @joyeecheung
    Member

    I guess this is fixed now that git-node-land has landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions