-
Notifications
You must be signed in to change notification settings - Fork 649
206 lines (181 loc) · 7.19 KB
/
owner-notification.yml
File metadata and controls
206 lines (181 loc) · 7.19 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
name: Owner Notification
on:
pull_request_target:
types: [assigned, opened, reopened, synchronize, ready_for_review]
jobs:
notify-owners:
if: >-
${{
github.repository == 'vllm-project/semantic-router' &&
!github.event.pull_request.draft
}}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: ${{ github.event.pull_request.base.sha }}
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: actions/github-script@v7
with:
result-encoding: string
script: |
// Retrieve changed files via GitHub API to avoid relying on fork
// refs.
const files = await github.paginate(github.rest.pulls.listFiles, {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
per_page: 100,
});
const filenames = files.map(f => f.filename);
core.setOutput('all_changed_files', filenames.join(' '));
- name: Find owners and notify
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
// Get changed files
const changedFiles =
`${{ steps.changed-files.outputs.all_changed_files }}`.split(' ');
console.log('Changed files:', changedFiles);
function readOwners(ownerPath) {
if (!fs.existsSync(ownerPath)) {
return [];
}
return fs.readFileSync(ownerPath, 'utf8')
.split('\n')
.map(line => line.trim())
.filter(line => line.startsWith('@'));
}
// Find the nearest OWNER file by walking from the changed file's
// directory back toward the repository root.
function findOwnerFile(filePath) {
let currentDir = path.dirname(filePath);
while (currentDir && currentDir !== '.') {
const ownerPath = path.join(currentDir, 'OWNER');
const owners = readOwners(ownerPath);
if (owners.length > 0) {
return { path: currentDir, owners };
}
const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
break;
}
currentDir = parentDir;
}
const rootOwners = readOwners('OWNER');
if (rootOwners.length > 0) {
return { path: '.', owners: rootOwners };
}
return null;
}
// Collect all owners for changed files
const ownerMap = new Map();
for (const file of changedFiles) {
if (!file.trim()) continue;
const ownerInfo = findOwnerFile(file);
if (ownerInfo) {
if (!ownerMap.has(ownerInfo.path)) {
ownerMap.set(ownerInfo.path, {
owners: ownerInfo.owners,
files: []
});
}
ownerMap.get(ownerInfo.path).files.push(file);
}
}
if (ownerMap.size === 0) {
console.log('No owners found for changed files');
return;
}
// Collect all unique owners for assignment
const allOwners = new Set();
for (const [, info] of ownerMap) {
for (const owner of info.owners) {
// Remove @ prefix for API call
allOwners.add(owner.replace('@', ''));
}
}
// Assign owners to the PR
if (allOwners.size > 0) {
try {
await github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
assignees: Array.from(allOwners)
});
console.log(
`Assigned PR to: ${Array.from(allOwners).join(', ')}`
);
} catch (error) {
console.log(`Failed to assign PR: ${error.message}`);
// Continue with comment creation even if assignment fails
}
}
// Create comment content
let commentBody = '## 👥 vLLM Semantic Team Notification\n\n';
commentBody +=
'The following members have been identified for the changed ' +
'files in this PR and have been automatically assigned:\n\n';
for (const [dirPath, info] of ownerMap) {
commentBody +=
`### 📁 \`${dirPath === '.' ? 'Root Directory' : dirPath}\`\n`;
commentBody += `**Owners:** ${info.owners.join(', ')}\n`;
commentBody += `**Files changed:**\n`;
for (const file of info.files) {
commentBody += `- \`${file}\`\n`;
}
commentBody += '\n';
}
commentBody += '---\n';
commentBody += '<div align="center">\n';
commentBody +=
'<img src="https://raw.githubusercontent.com/' +
'vllm-project/semantic-router/main/website/static/' +
'img/repo.png" ' +
'alt="vLLM" width="80%"/>';
commentBody += '</div>\n\n';
commentBody += '## 🎉 Thanks for your contributions!\n\n';
commentBody +=
'*This comment was automatically generated based on the OWNER ' +
'files in the repository.*';
// Get existing comments
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
// Check if we already have an owner notification comment
const existingComment = comments.find(comment =>
comment.user.login === 'github-actions[bot]' &&
comment.body.includes('## 👥 vLLM Semantic Team Notification')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody
});
console.log('Updated existing owner notification comment');
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});
console.log('Created new owner notification comment');
}