forked from tech-conferences/conference-data
-
Notifications
You must be signed in to change notification settings - Fork 0
255 lines (222 loc) · 13.5 KB
/
pr_check.yml
File metadata and controls
255 lines (222 loc) · 13.5 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
name: PR Check
on:
pull_request:
types: [opened]
paths:
- 'conferences/*/*.json'
jobs:
check-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Check if PR is dev-related
id: check-dev-related
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
// High-confidence development-related keywords (score: +3)
const HIGH_CONFIDENCE_KEYWORDS = [
"frontend", "backend", "fullstack", "devops", "javascript", "typescript",
"react", "angular", "vue", "node.js", "nodejs", "python", "java",
"ruby", "golang", "rust", "scala", "kotlin", "swift", "php",
"dotnet", ".net", "c#", "cpp", "c++", "elixir", "haskell", "clojure",
"programming", "developer", "coding", "software development",
"web development", "mobile development", "app development",
"git", "github", "gitlab", "docker", "kubernetes", "microservices",
"api development", "rest api", "graphql", "database design",
"sql", "nosql", "mongodb", "postgresql", "redis", "ci/cd",
"test automation", "unit testing", "integration testing"
];
// Medium-confidence keywords (score: +2)
const MEDIUM_CONFIDENCE_KEYWORDS = [
"software", "programming", "developer", "engineering", "code",
"framework", "library", "open source", "opensource", "agile", "scrum",
"architecture", "infrastructure", "cloud computing", "serverless",
"container", "deployment", "version control", "debugging"
];
// Low-confidence keywords (score: +1) - only count if combined with others
const LOW_CONFIDENCE_KEYWORDS = [
"tech", "technology", "digital", "innovation", "platform",
"system", "network", "security", "performance", "automation"
];
// Exclusion keywords that indicate non-dev conferences (score: -5)
const EXCLUSION_KEYWORDS = [
"medicine", "medical", "health", "healthcare", "clinical", "pharmaceutical",
"biology", "biomedical", "stem cell", "vaccine", "immunology",
"climate", "environment", "energy", "renewable", "sustainability",
"finance", "banking", "accounting", "economics", "business management",
"marketing", "sales", "hr", "human resources", "education", "teaching",
"psychology", "sociology", "law", "legal", "agriculture", "farming",
"chemistry", "physics", "mathematics", "statistics", "research",
"academic", "scientific", "conference on", "symposium on", "workshop on",
"semiconductor", "optoelectronics", "photonics", "electronics", "electrical",
"hardware", "mechanical", "materials", "nanotechnology", "nanoscience",
"sensors", "signal processing", "robotics", "automation", "manufacturing",
"aerospace", "automotive", "telecommunications", "wireless", "circuits",
"embedded systems", "microelectronics", "bioengineering", "chemical engineering"
];
// Function to calculate dev-relatedness score
function calculateDevScore(conferenceName) {
const lowerName = conferenceName.toLowerCase();
let score = 0;
// Check for exclusion keywords first
for (const keyword of EXCLUSION_KEYWORDS) {
if (lowerName.includes(keyword.toLowerCase())) {
score -= 5;
}
}
// Check high confidence keywords
for (const keyword of HIGH_CONFIDENCE_KEYWORDS) {
if (lowerName.includes(keyword.toLowerCase())) {
score += 3;
}
}
// Check medium confidence keywords
for (const keyword of MEDIUM_CONFIDENCE_KEYWORDS) {
if (lowerName.includes(keyword.toLowerCase())) {
score += 2;
}
}
// Check low confidence keywords
for (const keyword of LOW_CONFIDENCE_KEYWORDS) {
if (lowerName.includes(keyword.toLowerCase())) {
score += 1;
}
}
return score;
}
// Function to check if a conference name is dev-related
function isDevRelated(conferenceName) {
const score = calculateDevScore(conferenceName);
// Require a minimum score of 3 to be considered dev-related
return score >= 3;
}
// Check if we're running in a real PR context or in a test environment
try {
// Make sure we have a valid PR number
if (!context.issue.number) {
console.log("No PR number found, assuming test environment.");
return 'test-mode';
}
// Get the list of files changed in the PR
const response = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
// Filter for conference JSON files
const conferenceFiles = response.data.filter(file =>
file.filename.match(/conferences\/.*\/.*\.json/));
console.log(`Found ${conferenceFiles.length} conference files in PR:`);
conferenceFiles.forEach(file => {
console.log(`- ${file.filename} (status: ${file.status})`);
});
if (conferenceFiles.length === 0) {
console.log("No conference files found in this PR");
return 'false';
} // For each conference file, check its content
for (const file of conferenceFiles) {
try {
console.log(`\n=== Processing file: ${file.filename} ===`);
// Get the diff for this specific file to see only what was added
const diffResponse = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
headers: {
accept: 'application/vnd.github.v3.diff'
}
});
// Parse the diff to extract only added lines for this file
const diffText = diffResponse.data;
const fileDiffs = diffText.split('diff --git');
let addedConferencesText = '';
for (const fileDiff of fileDiffs) {
if (fileDiff.includes(`a/${file.filename}`) && fileDiff.includes(`b/${file.filename}`)) {
// Found the diff for our file
const lines = fileDiff.split('\n');
for (const line of lines) {
if (line.startsWith('+') && !line.startsWith('+++')) {
// This is an added line
addedConferencesText += line.substring(1) + '\n';
}
}
break;
}
}
console.log(`Added content:\n${addedConferencesText}`);
// Extract conference names from added content using regex
const nameMatches = addedConferencesText.match(/"name":\s*"([^"]+)"/g);
if (!nameMatches) {
console.log(`No conference names found in added content for ${file.filename}`);
continue;
}
const addedConferenceNames = nameMatches.map(match => {
const nameMatch = match.match(/"name":\s*"([^"]+)"/);
return nameMatch ? nameMatch[1] : null;
}).filter(name => name !== null);
console.log(`Found ${addedConferenceNames.length} new conferences in ${file.filename}:`);
addedConferenceNames.forEach(name => console.log(`- ${name}`));
// Check each new conference
for (const conferenceName of addedConferenceNames) {
const score = calculateDevScore(conferenceName);
console.log(`Conference: "${conferenceName}" - Score: ${score} (NEWLY ADDED to ${file.filename})`);
if (isDevRelated(conferenceName)) {
console.log(`Found dev-related NEW conference: ${conferenceName} in file ${file.filename}`);
return 'true';
}
}
} catch (fileError) {
console.log(`Error accessing content of ${file.filename}: ${fileError.message}`);
continue;
}
}
// If we checked all files and found no dev-related conferences
return 'false';
} catch (error) {
console.log(`Error accessing PR details: ${error.message}`);
console.log("Assuming test environment. Workflow validation should pass.");
return 'test-mode';
}
- name: Add labels and notify
if: steps.check-dev-related.outputs.result != 'test-mode'
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const isDev = '${{ steps.check-dev-related.outputs.result }}' === 'true';
try {
// Add appropriate label
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: [isDev ? 'dev-related' : 'non-dev-related']
});
// Add appropriate comment
if (isDev) {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '👨💻 A development-related conference has been detected!'
});
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'This PR appears to be non-dev-related based on conference content analysis. It has been labeled as `non-dev-related`. If you believe this is an error, please let us know. Thank you!'
});
}
} catch (error) {
console.log(`Error in labeling or commenting: ${error.message}`);
}
- name: Test mode notification
if: steps.check-dev-related.outputs.result == 'test-mode'
run: |
echo "Running in test mode - skipping GitHub API interactions."
echo "The workflow syntax is valid and ready for real PR processing."