npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

commit-and-pr

v1.0.4

Published

[![Build Status](https://travis-ci.org/lupomontero/commit-and-pr.svg?branch=master)](https://travis-ci.org/lupomontero/commit-and-pr) [![Coverage Status](https://coveralls.io/repos/github/lupomontero/commit-and-pr/badge.svg?branch=master)](https://coveral

Downloads

108

Readme

commit-and-pr

Build Status Coverage Status Greenkeeper badge

This is experimental and is meant to be used as part of an automated build process to be run on Travis CI.

Use case

A GitHub repo has some script that updates files that should then be commited and merged back on the repo. The initial use case is the psl repo, where we want to automate updating the Public Suffix List, as it changes regularly. See this issue.

The idea is that a Travis CI cron job will trigger a build script, which will detect that it has been triggered by a cron job and instead of running the tests, it will run our update script, and if it resulted in unstaged changes, it will automatically send a pull request with the changes.

Installation

npm i --save-dev commit-and-pr

Usage

CLI

GH_TOKEN=XXX TRAVIS_REPO_SLUG=github-user/repo-name npx commit-and-pr "Some commit message"

Environment variables

  • GH_TOKEN: A GitHub Personal access token with write access to the repo. This is needed in order to push changes back to GitHub and send a Pull Request.
  • TRAVIS_REPO_SLUG: The repo slug (ie: github-user/repo-name). If your build id running on Travis CI this is already set in the environment.

Optional git related env vars:

  • EMAIL: Fallback for GIT_AUTHOR_EMAIL and GIT_COMMITTER_EMAIL.
  • GIT_AUTHOR_NAME: The human readable author name.
  • GIT_AUTHOR_EMAIL: (optional). If not present will default to EMAIL.
  • GIT_COMMITTER_NAME: The human readable committer name.
  • GIT_COMMITTER_EMAIL: (optional). If not present will default to EMAIL.

In case (some of) these environment variables are not set, the information is taken from the configuration items user.name and user.email, or, if not present, the environment variable EMAIL, or, if that is not set, system user name and the hostname used for outgoing mail [...]

See: https://git-scm.com/docs/git-commit-tree#_commit_information

npm-scripts

Let's pretend that our update script can be run as npm run update.

package.json:

{
  ...
  "scripts": {
    "update": "date > date.out",
    "commit-and-pr": "commit-and-pr"
  },
  ...
}
npm run update && npm run commit-and-pr "Some commit message"

Travis CI

Continuing with the npm-scripts example...

travis encrypt GH_TOKEN=<YOUR-GITHUB-PERSONAL-ACCESS-TOKEN>

.travis.yml:

language: node_js
node_js:
  - 10
  - 12
script: ./scripts/build.sh
env:
  - secure: "XXXX="

./scripts/build.sh:

#! /usr/bin/env bash


if [[ "$TRAVIS_EVENT_TYPE" != "cron" ]]; then
  echo "Not triggered by cron. Running tests..."
  npm test
else
  echo "Triggered by cron. Running update script..."
  npm run update && npm run commit-and-pr "Some commit message"
fi

API

Promise commitAndPullRequest(msg, opts)

Options

  • cwd
  • env
  • stdout
  • stderr

Example

const commitAndPullRequest = require('commit-and-pr');
const { cwd, env, stdout, stderr } = process;

commitAndPullRequest('commit message', {
  cwd: cwd(),
  env,
  stdio: ['ignore', stdout, stderr],
})
  .then(console.log)
  .catch(console.error);

What does it do?

  1. Checks if there are unstaged changes in local copy (git diff-index ...)
  • if no unstaged changes there's nothing to do.
  • else move to step 2
  1. Creates a new branch (git checkout -b ...)
  2. adds changes (git add .)
  3. commits them (git commit ...)
  4. add remote (git remote add origin-with-token ...)
  5. pushes to GitHub (git push origin-with-token ...)
  6. creates PR (using GitHub REST API)