2727
2828// Configuration
2929const INCLUDE_POLL_MERMAID_CHART = true ; // Set to false to disable Mermaid pie chart for polls
30+ const RATE_LIMIT_SLEEP_SECONDS = 2 ; // Default sleep duration between API calls to avoid rate limiting
3031
3132const { Octokit } = require ( "octokit" ) ;
3233
@@ -136,7 +137,7 @@ async function sleep(seconds) {
136137 return new Promise ( resolve => setTimeout ( resolve , seconds * 1000 ) ) ;
137138}
138139
139- async function rateLimitSleep ( seconds = 2 ) {
140+ async function rateLimitSleep ( seconds = RATE_LIMIT_SLEEP_SECONDS ) {
140141 log ( `Waiting ${ seconds } s to avoid rate limiting...` ) ;
141142 await sleep ( seconds ) ;
142143}
@@ -493,7 +494,7 @@ const MARK_DISCUSSION_COMMENT_AS_ANSWER_MUTATION = `
493494async function checkDiscussionsEnabled ( octokit , owner , repo ) {
494495 log ( `Checking if discussions are enabled in ${ owner } /${ repo } ...` ) ;
495496
496- await rateLimitSleep ( 2 ) ;
497+ await rateLimitSleep ( ) ;
497498
498499 try {
499500 const response = await octokit . graphql ( CHECK_DISCUSSIONS_ENABLED_QUERY , {
@@ -517,7 +518,7 @@ async function checkDiscussionsEnabled(octokit, owner, repo) {
517518async function fetchCategories ( octokit , owner , repo ) {
518519 log ( `Fetching categories from ${ owner } /${ repo } ...` ) ;
519520
520- await rateLimitSleep ( 2 ) ;
521+ await rateLimitSleep ( ) ;
521522
522523 try {
523524 const response = await octokit . graphql ( FETCH_CATEGORIES_QUERY , {
@@ -538,7 +539,7 @@ async function fetchCategories(octokit, owner, repo) {
538539async function fetchLabels ( octokit , owner , repo ) {
539540 log ( `Fetching labels from ${ owner } /${ repo } ...` ) ;
540541
541- await rateLimitSleep ( 2 ) ;
542+ await rateLimitSleep ( ) ;
542543
543544 try {
544545 const response = await octokit . graphql ( FETCH_LABELS_QUERY , {
@@ -606,7 +607,7 @@ function findLabelId(labels, labelName) {
606607async function createLabel ( octokit , repositoryId , name , color , description , targetLabels ) {
607608 log ( `Creating new label: '${ name } '` ) ;
608609
609- await rateLimitSleep ( 2 ) ;
610+ await rateLimitSleep ( ) ;
610611
611612 try {
612613 const response = await octokit . graphql ( CREATE_LABEL_MUTATION , {
@@ -651,7 +652,7 @@ async function addLabelsToDiscussion(octokit, discussionId, labelIds) {
651652
652653 log ( `Adding ${ labelIds . length } labels to discussion` ) ;
653654
654- await rateLimitSleep ( 2 ) ;
655+ await rateLimitSleep ( ) ;
655656
656657 try {
657658 await octokit . graphql ( ADD_LABELS_MUTATION , {
@@ -719,7 +720,7 @@ async function createDiscussion(octokit, repositoryId, categoryId, title, body,
719720async function lockDiscussion ( octokit , discussionId ) {
720721 log ( `Locking discussion ${ discussionId } ...` ) ;
721722
722- await rateLimitSleep ( 2 ) ;
723+ await rateLimitSleep ( ) ;
723724
724725 try {
725726 await octokit . graphql ( LOCK_DISCUSSION_MUTATION , {
@@ -734,7 +735,7 @@ async function lockDiscussion(octokit, discussionId) {
734735async function fetchDiscussionComments ( octokit , discussionId ) {
735736 log ( `Fetching comments for discussion ${ discussionId } ...` ) ;
736737
737- await rateLimitSleep ( 2 ) ;
738+ await rateLimitSleep ( ) ;
738739
739740 try {
740741 const response = await octokit . graphql ( FETCH_DISCUSSION_COMMENTS_QUERY , {
@@ -761,7 +762,7 @@ async function addDiscussionComment(octokit, discussionId, body, originalAuthor,
761762
762763 log ( "Adding comment to discussion" ) ;
763764
764- await rateLimitSleep ( 2 ) ;
765+ await rateLimitSleep ( ) ;
765766
766767 try {
767768 const response = await octokit . graphql ( ADD_DISCUSSION_COMMENT_MUTATION , {
@@ -791,7 +792,7 @@ async function addDiscussionCommentReply(octokit, discussionId, replyToId, body,
791792
792793 log ( `Adding reply to comment ${ replyToId } ` ) ;
793794
794- await rateLimitSleep ( 2 ) ;
795+ await rateLimitSleep ( ) ;
795796
796797 try {
797798 const response = await octokit . graphql ( ADD_DISCUSSION_COMMENT_REPLY_MUTATION , {
@@ -812,7 +813,7 @@ async function addDiscussionCommentReply(octokit, discussionId, replyToId, body,
812813async function closeDiscussion ( octokit , discussionId ) {
813814 log ( "Closing discussion..." ) ;
814815
815- await rateLimitSleep ( 2 ) ;
816+ await rateLimitSleep ( ) ;
816817
817818 try {
818819 await octokit . graphql ( CLOSE_DISCUSSION_MUTATION , {
@@ -831,7 +832,7 @@ async function closeDiscussion(octokit, discussionId) {
831832async function markCommentAsAnswer ( octokit , commentId ) {
832833 log ( "Marking comment as answer..." ) ;
833834
834- await rateLimitSleep ( 2 ) ;
835+ await rateLimitSleep ( ) ;
835836
836837 try {
837838 await octokit . graphql ( MARK_DISCUSSION_COMMENT_AS_ANSWER_MUTATION , {
0 commit comments