Skip to content

Instantly share code, notes, and snippets.

@hachesilva
Forked from yzdbg/auto-dr.md
Created June 2, 2023 19:49
Show Gist options
  • Save hachesilva/f5634a586f4cf88020867fe8fd9f9aaa to your computer and use it in GitHub Desktop.
Save hachesilva/f5634a586f4cf88020867fe8fd9f9aaa to your computer and use it in GitHub Desktop.

Automating Daily Reports, because fuck it, really...

Each day at our company, developers are required to document their activities, painstakingly jotting down their daily work and future plans. A monotonous chore that I just really dislike.

So now, there's a scribe for that :

auto-dr-

Code

const { execSync } = require("child_process");

// Get the current day and tomorrow's day
const currentDay = new Date().toLocaleDateString("en-US", { weekday: "long" });
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const nextDay = tomorrow.toLocaleDateString("en-US", { weekday: "long" });

// Get the current user from Git configuration
const currentUser = execSync("git config user.name").toString().trim();

// Set the start of the day
const startOfDay = `${currentDay}T00:00:00`;

// Display the current day
console.log(`*${currentDay}*`);

// Get the list of branches
const branches = execSync('git branch --format="%(refname:short)" --no-column')
  .toString()
  .trim()
  .split("\n");

// Iterate through each branch
branches.forEach((branch) => {
  // Get the commits made by the current user since the start of the day on the specific branch
  const commits = execSync(
    `git log --author="${currentUser}" --since="${startOfDay}" --pretty=format:'- %s' ${branch}`
  )
    .toString()
    .trim();

  // If there are commits, display them under the branch header
  if (commits) {
    console.log(`*Branch: ${branch}*`);
    console.log(commits);
    console.log();
  }
});

// Display tomorrow's day
console.log(`*${nextDay}*`);
console.log("-");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment