mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-11-03 03:16:10 -06:00 
			
		
		
		
	Chore: Close outdated support / general discussions (#5443)
This commit is contained in:
		
							
								
								
									
										91
									
								
								.github/workflows/repo-maintenance.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										91
									
								
								.github/workflows/repo-maintenance.yml
									
									
									
									
										vendored
									
									
								
							@@ -107,3 +107,94 @@ jobs:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
              await sleep(1000)
 | 
					              await sleep(1000)
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					  close-outdated-discussions:
 | 
				
			||||||
 | 
					    name: 'Close Outdated Discussions'
 | 
				
			||||||
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
 | 
					    steps:
 | 
				
			||||||
 | 
					      - uses: actions/github-script@v7
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          script: |
 | 
				
			||||||
 | 
					            function sleep(ms) {
 | 
				
			||||||
 | 
					              return new Promise(resolve => setTimeout(resolve, ms));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const CUTOFF_DAYS = 180;
 | 
				
			||||||
 | 
					            const cutoff = new Date();
 | 
				
			||||||
 | 
					            cutoff.setDate(cutoff.getDate() - CUTOFF_DAYS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            const query = `query(
 | 
				
			||||||
 | 
					                $owner:String!,
 | 
				
			||||||
 | 
					                $name:String!,
 | 
				
			||||||
 | 
					                $supportCategory:ID!,
 | 
				
			||||||
 | 
					                $generalCategory:ID!,
 | 
				
			||||||
 | 
					              ) {
 | 
				
			||||||
 | 
					              supportDiscussions: repository(owner:$owner, name:$name){
 | 
				
			||||||
 | 
					                discussions(
 | 
				
			||||||
 | 
					                  categoryId:$supportCategory,
 | 
				
			||||||
 | 
					                  last:50,
 | 
				
			||||||
 | 
					                  answered:false,
 | 
				
			||||||
 | 
					                  states:[OPEN],
 | 
				
			||||||
 | 
					                ) {
 | 
				
			||||||
 | 
					                  nodes {
 | 
				
			||||||
 | 
					                    id,
 | 
				
			||||||
 | 
					                    number,
 | 
				
			||||||
 | 
					                    updatedAt
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					              },
 | 
				
			||||||
 | 
					              generalDiscussions: repository(owner:$owner, name:$name){
 | 
				
			||||||
 | 
					                discussions(
 | 
				
			||||||
 | 
					                  categoryId:$generalCategory,
 | 
				
			||||||
 | 
					                  last:50,
 | 
				
			||||||
 | 
					                  states:[OPEN],
 | 
				
			||||||
 | 
					                ) {
 | 
				
			||||||
 | 
					                  nodes {
 | 
				
			||||||
 | 
					                    id,
 | 
				
			||||||
 | 
					                    number,
 | 
				
			||||||
 | 
					                    updatedAt
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }`;
 | 
				
			||||||
 | 
					            const variables = {
 | 
				
			||||||
 | 
					              owner: context.repo.owner,
 | 
				
			||||||
 | 
					              name: context.repo.repo,
 | 
				
			||||||
 | 
					              supportCategory: "DIC_kwDOG1Zs184CBKWK",
 | 
				
			||||||
 | 
					              generalCategory: "DIC_kwDOG1Zs184CBKWJ"
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            const result = await github.graphql(query, variables);
 | 
				
			||||||
 | 
					            const combinedDiscussions = [
 | 
				
			||||||
 | 
					              ...result.supportDiscussions.discussions.nodes,
 | 
				
			||||||
 | 
					              ...result.generalDiscussions.discussions.nodes,
 | 
				
			||||||
 | 
					            ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            console.log(`Checking ${combinedDiscussions.length} open discussions`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            for (const discussion of combinedDiscussions) {
 | 
				
			||||||
 | 
					              if (new Date(discussion.updatedAt) < cutoff) {
 | 
				
			||||||
 | 
					                console.log(`Closing outdated discussion #${discussion.number} (${discussion.id}), last updated at ${discussion.updatedAt}`);
 | 
				
			||||||
 | 
					                const addCommentMutation = `mutation($discussion:ID!, $body:String!) {
 | 
				
			||||||
 | 
					                  addDiscussionComment(input:{discussionId:$discussion, body:$body}) {
 | 
				
			||||||
 | 
					                    clientMutationId
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                }`;
 | 
				
			||||||
 | 
					                const commentVariables = {
 | 
				
			||||||
 | 
					                  discussion: discussion.id,
 | 
				
			||||||
 | 
					                  body: 'This discussion has been automatically closed due to inactivity.',
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                await github.graphql(addCommentMutation, commentVariables);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                const closeDiscussionMutation = `mutation($discussion:ID!, $reason:DiscussionCloseReason!) {
 | 
				
			||||||
 | 
					                  closeDiscussion(input:{discussionId:$discussion, reason:$reason}) {
 | 
				
			||||||
 | 
					                    clientMutationId
 | 
				
			||||||
 | 
					                  }
 | 
				
			||||||
 | 
					                }`;
 | 
				
			||||||
 | 
					                const closeVariables = {
 | 
				
			||||||
 | 
					                  discussion: discussion.id,
 | 
				
			||||||
 | 
					                  reason: "OUTDATED",
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                await github.graphql(closeDiscussionMutation, closeVariables);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                await sleep(1000);
 | 
				
			||||||
 | 
					              }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user