Today I Learned

Group Dependabot Updates into One Pull Request

To group Dependabot version updates into a single pull request, you can customize the configuration in the dependabot.yml file. Specify the package ecosystem (e.g., npm) and the directory where package manifests are located. Use the groups feature to define how updates should be bundled. For instance, in the example configuration, all version updates are grouped under a single PR by specifying a group named dependencies with a wildcard pattern that applies to all version updates. See the documentation for more details.

version: 2
updates:
  - package-ecosystem: 'npm'
    directory: '/'
    schedule:
      interval: 'weekly'
    commit-message:
      prefix: 'deps: '
    groups:
      dependencies:
        patterns:
          - '*'

Mock HTTP Requests in Node.js with Undici

import { MockAgent, setGlobalDispatcher } from 'undici';
 
const mockAgent = new MockAgent();
setGlobalDispatcher(mockAgent);
 
const mockPool = mockAgent.get('http://localhost:3000');
 
mockPool
  .intercept({
    path: '/me',
    method: 'GET',
  })
  .reply(200, {
    id: '123',
    name: 'Johnie',
  });
 
fetch('http://localhost:3000/me')
  .then((res) => res.json())
  .then((user) => {
    console.dir(user); // { id: '123', name: 'Johnie' }
  });

Formatting Commit Messages with fmt

You can use the fmt command to format commit messages in Git for better readability. Here's a useful command:

fmt -n -p -w 80
  • -n: Preserves indented lines, making bullet points or code snippets in the message clear.
  • -p: Avoids formatting lines that already begin with indentation, useful for keeping lists and indented code unchanged.
  • -w 80: Wraps text at 80 characters, which is a common convention for commit message width.