forked from langchain-ai/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
109 lines (95 loc) · 3.84 KB
/
check-default-title.yml
File metadata and controls
109 lines (95 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
---
name: Check for Default Title
on:
issues:
types: [opened, edited]
pull_request_target:
types: [opened, edited]
jobs:
check-default-title:
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
issues: write
pull-requests: write
steps:
- name: Check title and comment if default
uses: actions/github-script@v8
with:
script: |
const isIssue = context.eventName === 'issues';
const item = isIssue ? context.payload.issue : context.payload.pull_request;
const title = item.title;
const itemNumber = item.number;
const itemType = isIssue ? 'issue' : 'pull request';
// Check for default placeholder text in title
const hasDefaultTitle =
title.includes('<Please write a comprehensive title>') ||
title.toLowerCase().includes('documentation issue');
if (!hasDefaultTitle) {
console.log(`Title is descriptive: "${title}"`);
// Remove needs-title label if present
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: itemNumber,
name: 'needs-title',
});
console.log(`Removed 'needs-title' label from ${itemType} #${itemNumber}`);
} catch (error) {
// Label not present, that's fine
}
return;
}
console.log(`Default title detected: "${title}"`);
// Check if we've already commented on this item
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: itemNumber,
});
const botComment = comments.data.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('<!-- default-title-check -->')
);
if (botComment) {
console.log('Already commented on this item, skipping.');
return;
}
// Add comment explaining they need a descriptive title
const commentBody = [
'<!-- default-title-check -->',
'',
`**Please update the title of this ${itemType}.**`,
'',
`The current title contains the default placeholder text. A descriptive title helps maintainers understand and prioritize your ${itemType}.`,
'',
'**Good titles:**',
'- "Missing example for streaming with tool calls"',
'- "Typo in LangGraph quickstart guide"',
'- "Add documentation for SummarizationMiddleware"',
'',
`**Please edit the title** to briefly describe your ${itemType}. Until then, this ${itemType} may not receive attention from maintainers.`,
'',
'Thank you for contributing!',
].join('\n');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: itemNumber,
body: commentBody,
});
// Add a label to make it easy to filter
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: itemNumber,
labels: ['needs-title'],
});
} catch (error) {
// Label might not exist, that's okay
console.log('Could not add label (may not exist):', error.message);
}
console.log(`Commented on ${itemType} #${itemNumber}`);