Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 29, 2021 08:39 pm GMT

Highlighting: sync-contribution-graph

A couple of weeks ago, I nearly scrolled past this gem on my twitter feed: sync-contribution-graph, by @kefimochi. Go have a look!

You can use this tool to have your GitHub contribution graph accurately reflect contributions from other accounts you make use of. For example, outside of work I use the handle mtfoley, but I have a separate account I use for my job. I like the idea that I could use this to accurately reflect my activity level, and that no private information about that work handle is revealed.

The way it works is pretty straightforward. When you configure it with a username and a time frame (year), it performs an HTTP request to the appropriate URL, and parses the HTML in the response for the dates/counts of contributions (these correspond to those little green squares). Based on this data, it creates appropriate git shell commands. The shell commands are saved to a file that can optionally be run immediately. Here's a snippet that's the meat of it in src/index.js:

import { parse } from "node-html-parser";import axios from "axios";import fs from "fs";import shell from "shelljs";// Gathers needed git commands for bash to execute per provided contribution data.const getCommand = (contribution) => {  return `GIT_AUTHOR_DATE=${contribution.date}T12:00:00 GIT_COMMITER_DATE=${contribution.date}T12:00:00 git commit --allow-empty -m "Rewriting History!" > /dev/null
`
.repeat( contribution.count );};export default async (input) => { // Returns contribution graph html for a full selected year. const res = await axios.get( `https://github.com/users/${input.username}/contributions?tab=overview&from=${input.year}-12-01&to=${input.year}-12-31` ); // Retrieves needed data from the html, loops over green squares with 1+ contributions, // and produces a multi-line string that can be run as a bash command. const script = parse(res.data) .querySelectorAll("[data-count]") .map((el) => { return { date: el.attributes["data-date"], count: parseInt(el.attributes["data-count"]), }; }) .filter((contribution) => contribution.count > 0) .map((contribution) => getCommand(contribution)) .join("") .concat("git pull origin main
", "git push -f origin main"); fs.writeFile("script.sh", script, () => { console.log("
File was created successfully."); if (input.execute) { console.log("This might take a moment!
"); shell.exec("sh ./script.sh"); } });};

I made some suggestions in the setup workflow on the repo and submitted a PR to update the README. I hope you find this and other work by @kefimochi to be of interest!


Original Link: https://dev.to/mtfoley/highlighting-sync-contribution-graph-6o8

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To