File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ /* Fetch all open PRs and updates them with main branch.*/
2+
3+ const updatePrs = async ( { github, context } ) => {
4+ const { repo, owner } = context . repo ;
5+ const pulls = await github . rest . pulls . list ( {
6+ owner,
7+ repo,
8+ state : 'open' ,
9+ base : 'main' ,
10+ per_page : 100
11+ } ) ;
12+
13+ const nonDraftPulls = pulls ?. data ?. filter ( ( pr ) => ! pr . draft ) ;
14+ let updatedBranches = 0 ;
15+
16+ if ( nonDraftPulls ?. length > 0 ) {
17+ for ( const pr of nonDraftPulls ) {
18+ try {
19+ await github . rest . pulls . updateBranch ( {
20+ owner,
21+ repo,
22+ pull_number : pr . number
23+ } ) ;
24+ updatedBranches ++ ;
25+ } catch ( e ) {
26+ console . error ( e ) ;
27+ }
28+ }
29+ }
30+
31+ return `Updated branches: ${ updatedBranches } /${ nonDraftPulls . length } ` ;
32+ } ;
33+
34+ export default updatePrs ;
You can’t perform that action at this time.
0 commit comments