Commit 31a2642
Changed files (6)
src
src/all-badges/emoji-only-commit/emoji-only-commit.ts
@@ -4,11 +4,11 @@ export default new (class implements BadgePresenter {
url = new URL(import.meta.url)
badges = ['emoji-only-commit'] as const
present: Present = (data, grant) => {
- const commits = data.repos.flatMap(repo =>
- repo.commits.filter(commit =>
- /^(\p{Emoji}|\s)+$/u.test(commit.message + commit.messageBody)
- )
- );
+ const commits = data.repos.flatMap((repo) =>
+ repo.commits.filter((commit) =>
+ /^(\p{Emoji}|\s)+$/u.test(commit.message + commit.messageBody),
+ ),
+ )
if (commits.length > 0) {
grant(
src/main.ts
@@ -7,7 +7,7 @@ import { throttling } from '@octokit/plugin-throttling'
import { presentBadges } from './present-badges.js'
import { getData } from './get-data.js'
import { allBadges } from './all-badges/index.js'
-import { getUserBadges, gitClone, gitPush } from './repo.js'
+import { getUserBadges, gitClone, gitPush, thereAreChanges } from './repo.js'
import { updateBadges } from './update-badges.js'
import { updateReadme } from './update-readme.js'
@@ -75,7 +75,7 @@ void (async function main() {
if (owner && repo) {
updateBadges(userBadges)
updateReadme(userBadges, size)
- if (!dryrun) {
+ if (!dryrun && thereAreChanges()) {
gitPush()
}
}
src/repo.ts
@@ -1,7 +1,7 @@
import fs from 'node:fs'
import { chdir } from 'node:process'
import { Badge } from './badges.js'
-import { exec } from './utils.js'
+import { exec, execWithOutput } from './utils.js'
export function gitClone(owner: string, repo: string, token: string) {
exec('git', [
@@ -19,6 +19,16 @@ export function gitClone(owner: string, repo: string, token: string) {
chdir('..')
}
+export function thereAreChanges(): boolean {
+ chdir('repo')
+
+ const changes = execWithOutput('git', ['status', '--porcelain']).trim()
+
+ chdir('..')
+
+ return changes !== ''
+}
+
export function gitPush() {
chdir('repo')
src/utils.ts
@@ -1,4 +1,3 @@
-import process from 'node:process'
import { spawnSync } from 'node:child_process'
import { Commit, Issue, Pull } from './collect/collect.js'
@@ -39,3 +38,11 @@ export function exec(command: string, args: string[]): void {
throw new Error(`Command failed: ${command} ${args.join(' ')}`)
}
}
+
+export function execWithOutput(command: string, args: string[]): string {
+ const p = spawnSync(command, args, { stdio: 'pipe' })
+ if (p.status !== 0) {
+ throw new Error(`Command failed: ${command} ${args.join(' ')}`)
+ }
+ return p.stdout.toString()
+}
package-lock.json
@@ -1,12 +1,12 @@
{
"name": "update-my-badges",
- "version": "1.0.121",
+ "version": "1.0.122",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "update-my-badges",
- "version": "1.0.121",
+ "version": "1.0.122",
"license": "MIT",
"dependencies": {
"@octokit/plugin-retry": "^6.0.1",
package.json
@@ -1,6 +1,6 @@
{
"name": "update-my-badges",
- "version": "1.0.121",
+ "version": "1.0.122",
"description": "Generate badges for your GitHub projects",
"type": "module",
"bin": {