From 4b59a9f5025386d66ff5f23ad283b030342bed35 Mon Sep 17 00:00:00 2001 From: chatton Date: Fri, 31 Jan 2025 10:16:46 +0000 Subject: [PATCH] chore: misc changes --- zx/clean_notifications.mjs | 24 ++++++++++++++++++++++++ zx/create_pr.mjs | 4 ++-- zx/lib/git.js | 35 ++++++++++++++++++++++++----------- zx/new_issue_branch.mjs | 2 +- 4 files changed, 51 insertions(+), 14 deletions(-) create mode 100755 zx/clean_notifications.mjs diff --git a/zx/clean_notifications.mjs b/zx/clean_notifications.mjs new file mode 100755 index 0000000..fc7f636 --- /dev/null +++ b/zx/clean_notifications.mjs @@ -0,0 +1,24 @@ +#!/usr/bin/env zx + +$.verbose = false; + +const git = await import("./lib/git.js") + +const notificationsOutput = await $`gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /notifications` +const notifications = JSON.parse(notificationsOutput.stdout); +const ibcGoNotifications = [] +for (let n of notifications) { + // console.log(n); + if (git.shouldDeleteNotification(n)) { + const id = n.id; + // const resp = await $`gh api -X DELETE -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /notifications/threads/${id}/subscription`; + // console.log(resp.stdout) + console.log(n) + } + + // + // if (n.repository.name === "ibc-go") { + // ibcGoNotifications.push(n); + // } +} + diff --git a/zx/create_pr.mjs b/zx/create_pr.mjs index 7adfc32..9d79c39 100755 --- a/zx/create_pr.mjs +++ b/zx/create_pr.mjs @@ -6,7 +6,7 @@ const git = await import("./lib/git.js") const issueNumber = process.argv[3]; const issue = await $`gh issue view ${issueNumber} --repo cosmos/ibc-go --json title`; -const issueTitle = JSON.parse(issue).title; +const issueTitle = JSON.parse(issue).title.trim(); const sanitizedTitle = git.sanitizeIssueTitle(issueTitle); -await $`gh pr create --web --title ${issueTitle} --base main` +await $`gh pr create --web --title "${sanitizedTitle}" --base main` diff --git a/zx/lib/git.js b/zx/lib/git.js index 1418c5f..5725e39 100644 --- a/zx/lib/git.js +++ b/zx/lib/git.js @@ -1,14 +1,27 @@ +module.exports.shouldDeleteNotification = function (n) { + // if (n.unread === false) { + // return true + // } -module.exports = { - sanitizeIssueTitle(issueTitle) { - let sanitizedTitle = issueTitle.trim().toLowerCase() - sanitizedTitle = sanitizedTitle.replaceAll(".", "") - sanitizedTitle = sanitizedTitle.replaceAll(",", "") - sanitizedTitle = sanitizedTitle.replaceAll("`", "") - sanitizedTitle = sanitizedTitle.replaceAll(":", "") - sanitizedTitle = sanitizedTitle.replaceAll("-", "") - - // replace the spaces with dashes after the dashes are removed. - return sanitizedTitle.replaceAll(" ", "-") + if (n.reason === 'ci_activity') { + // console.log(n) + return true } + + return false } + +module.exports.sanitizeIssueTitle = function (issueTitle) { + let sanitizedTitle = issueTitle.trim().toLowerCase() + sanitizedTitle = sanitizedTitle.replaceAll(".", "") + sanitizedTitle = sanitizedTitle.replaceAll(",", "") + sanitizedTitle = sanitizedTitle.replaceAll("`", "") + sanitizedTitle = sanitizedTitle.replaceAll(":", "") + sanitizedTitle = sanitizedTitle.replaceAll("-", "") + sanitizedTitle = sanitizedTitle.replaceAll("'", "") + sanitizedTitle = sanitizedTitle.replaceAll("’", "") + sanitizedTitle = sanitizedTitle.replaceAll("`", "") + sanitizedTitle = sanitizedTitle.replaceAll("(", "") + sanitizedTitle = sanitizedTitle.replaceAll(")", "") + return sanitizedTitle.replaceAll(" ", "-") +}; diff --git a/zx/new_issue_branch.mjs b/zx/new_issue_branch.mjs index 7650dcf..382c54d 100755 --- a/zx/new_issue_branch.mjs +++ b/zx/new_issue_branch.mjs @@ -10,7 +10,7 @@ const issue = await $`gh issue view ${issueNumber} --repo cosmos/ibc-go --json t const issueTitle = JSON.parse(issue).title; const sanitizedTitle = git.sanitizeIssueTitle(issueTitle); -if (extraString !== undefined) { +if (extraString) { extraString = "-" + extraString; } else { extraString = ""