@@ -38,6 +38,11 @@ function allIncluded(outputTarget = 'email') {
38
38
let issue_opened_button =
39
39
'<div style="vertical-align:middle;display: inline-block;padding: 0px 4px;font-size:9px;font-weight: 600;color: #fff;text-align: center;background-color: #2cbe4e;border-radius: 3px;line-height: 12px;margin-bottom: 2px;" class="State State--green">open</div>' ;
40
40
41
+ let pr_merged_true_button =
42
+ '<div style="vertical-align:middle;display: inline-block;padding: 0px 4px;font-size:9px;font-weight: 600;color: #fff;text-align: center;background-color: #6f42c1;border-radius: 3px;line-height: 12px;margin-bottom: 2px;" class="State State--purple">merged</div>' ;
43
+ let pr_merged_false_button =
44
+ '<div style="vertical-align:middle;display: inline-block;padding: 0px 4px;font-size:9px;font-weight: 600;color: #fff;text-align: center;background-color: #d73a49;border-radius: 3px;line-height: 12px;margin-bottom: 2px;" class="State State--red">closed</div>' ;
45
+
41
46
// let linkStyle = '';
42
47
function getChromeData ( ) {
43
48
console . log ( "Getting Chrome data for context:" , outputTarget ) ;
@@ -120,7 +125,7 @@ function allIncluded(outputTarget = 'email') {
120
125
if ( ! items . showClosedLabel ) {
121
126
showClosedLabel = false ;
122
127
pr_merged_button = '' ;
123
- issue_closed_button = '' ;
128
+
124
129
}
125
130
if ( items . userReason ) {
126
131
userReason = items . userReason ;
@@ -652,8 +657,7 @@ ${userReason}`;
652
657
prText +=
653
658
"<a href='" + pr_arr . html_url + "' target='_blank'>#" + pr_arr . number + '</a> (' + pr_arr . title + ') ' ;
654
659
if ( pr_arr . state === 'open' ) prText += issue_opened_button ;
655
- else prText += issue_closed_button ;
656
-
660
+ // Do not show closed label for reviewed PRs
657
661
prText += ' ' ;
658
662
repoLi += prText ;
659
663
}
@@ -671,8 +675,7 @@ ${userReason}`;
671
675
pr_arr1 . title +
672
676
') ' ;
673
677
if ( pr_arr1 . state === 'open' ) prText1 += issue_opened_button ;
674
- else prText1 += issue_closed_button ;
675
-
678
+ // Do not show closed label for reviewed PRs
676
679
prText1 += ' </li>' ;
677
680
repoLi += prText1 ;
678
681
}
@@ -698,14 +701,41 @@ ${userReason}`;
698
701
}
699
702
}
700
703
701
- function writeGithubIssuesPrs ( ) {
704
+ // Helper: calculate days between two yyyy-mm-dd strings
705
+ function getDaysBetween ( start , end ) {
706
+ const d1 = new Date ( start ) ;
707
+ const d2 = new Date ( end ) ;
708
+ return Math . ceil ( ( d2 - d1 ) / ( 1000 * 60 * 60 * 24 ) ) ;
709
+ }
710
+
711
+ // Helper to fetch PR details for merged status
712
+ async function fetchPrMergedStatus ( owner , repo , number , headers ) {
713
+ const url = `https://api.github.com/repos/${ owner } /${ repo } /pulls/${ number } ` ;
714
+ try {
715
+ const res = await fetch ( url , { headers } ) ;
716
+ if ( ! res . ok ) return null ;
717
+ const data = await res . json ( ) ;
718
+ return data . merged_at ? true : false ;
719
+ } catch ( e ) {
720
+ return null ;
721
+ }
722
+ }
723
+
724
+ // Update: make this async to allow merged status fetch and fallback
725
+ async function writeGithubIssuesPrs ( ) {
702
726
let items = githubIssuesData . items ;
703
727
lastWeekArray = [ ] ;
704
728
nextWeekArray = [ ] ;
705
729
if ( ! items ) {
706
730
logError ( 'No Github issues data available' ) ;
707
731
return ;
708
732
}
733
+ const headers = { 'Accept' : 'application/vnd.github.v3+json' } ;
734
+ if ( githubToken ) headers [ 'Authorization' ] = `token ${ githubToken } ` ;
735
+ let useMergedStatus = false ;
736
+ let fallbackToSimple = false ;
737
+ let daysRange = getDaysBetween ( startingDate , endingDate ) ;
738
+ if ( daysRange <= 14 ) useMergedStatus = true ;
709
739
for ( let i = 0 ; i < items . length ; i ++ ) {
710
740
let item = items [ i ] ;
711
741
let html_url = item . html_url ;
@@ -714,12 +744,32 @@ ${userReason}`;
714
744
let title = item . title ;
715
745
let number = item . number ;
716
746
let li = '' ;
717
-
718
747
if ( item . pull_request ) {
719
- if ( item . state === 'closed' ) {
720
- li = `<li><i>(${ project } )</i> - Made PR (#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ pr_merged_button } </li>` ;
721
- } else if ( item . state === 'open' ) {
748
+ if ( item . state === 'open' ) {
722
749
li = `<li><i>(${ project } )</i> - Made PR (#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ pr_unmerged_button } </li>` ;
750
+ } else if ( item . state === 'closed' ) {
751
+ if ( useMergedStatus && ! fallbackToSimple ) {
752
+ let owner = repository_url . split ( '/' ) [ repository_url . split ( '/' ) . length - 2 ] ;
753
+ let merged = null ;
754
+ try {
755
+ merged = await fetchPrMergedStatus ( owner , project , number , headers ) ;
756
+ if ( merged === true ) {
757
+ li = `<li><i>(${ project } )</i> - Made PR (#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ pr_merged_true_button } </li>` ;
758
+ } else if ( merged === false ) {
759
+ li = `<li><i>(${ project } )</i> - Made PR (#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ pr_merged_false_button } </li>` ;
760
+ } else {
761
+ li = `<li><i>(${ project } )</i> - Made PR (#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ pr_merged_false_button } </li>` ;
762
+ }
763
+ } catch ( e ) {
764
+ fallbackToSimple = true ;
765
+ li = `<li><i>(${ project } )</i> - Made PR (#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ pr_merged_button } </li>` ;
766
+ if ( typeof Materialize !== 'undefined' && Materialize . toast ) {
767
+ Materialize . toast ( 'API limit exceeded or error occurred. Please use a GitHub token for higher limits.' , 5000 ) ;
768
+ }
769
+ }
770
+ } else {
771
+ li = `<li><i>(${ project } )</i> - Made PR (#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ pr_merged_button } </li>` ;
772
+ }
723
773
}
724
774
} else {
725
775
// is a issue
@@ -741,6 +791,7 @@ ${userReason}`;
741
791
if ( item . state === 'open' ) {
742
792
li = `<li><i>(${ project } )</i> - Opened Issue(#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ issue_opened_button } </li>` ;
743
793
} else if ( item . state === 'closed' ) {
794
+ // Always show closed label for closed issues
744
795
li = `<li><i>(${ project } )</i> - Opened Issue(#${ number } ) - <a href='${ html_url } '>${ title } </a> ${ issue_closed_button } </li>` ;
745
796
} else {
746
797
li =
@@ -793,16 +844,16 @@ ${userReason}`;
793
844
} , 500 ) ;
794
845
795
846
//check for github safe writing
796
- let intervalWriteGithubIssues = setInterval ( ( ) => {
847
+ let intervalWriteGithubIssues = setInterval ( async ( ) => {
797
848
if ( outputTarget === 'popup' ) {
798
849
if ( githubUsername && githubIssuesData ) {
799
850
clearInterval ( intervalWriteGithubIssues ) ;
800
- writeGithubIssuesPrs ( ) ;
851
+ await writeGithubIssuesPrs ( ) ;
801
852
}
802
853
} else {
803
854
if ( scrumBody && githubUsername && githubIssuesData ) {
804
855
clearInterval ( intervalWriteGithubIssues ) ;
805
- writeGithubIssuesPrs ( ) ;
856
+ await writeGithubIssuesPrs ( ) ;
806
857
}
807
858
}
808
859
} , 500 ) ;
0 commit comments