forked from yakew7/Fair-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (51 loc) · 2.9 KB
/
Copy pathfirst.interaction.yml
File metadata and controls
59 lines (51 loc) · 2.9 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
name: First Interaction
on:
issues:
types: [opened]
pull_request_target:
types: [opened]
jobs:
greet:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Greet First-Time Contributor
uses: actions/github-script@v9
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const creator = context.payload.sender.login;
const owner = context.repo.owner;
const repo = context.repo.repo;
const number = context.issue.number;
const isPR = !!context.payload.pull_request;
const typeQuery = isPR ? 'is:pr' : 'is:issue';
// Find this author's earliest issue/PR of this type in the repo (#216).
// The search API's default sort is undocumented "best match" with no
// guaranteed order for a query with no free-text terms - it happens to
// come back newest-first today, but that's not a contract, so pin it
// explicitly to sort=created&order=asc. With that, the single oldest
// result answers "is this their first?" directly - no need to guess
// how many of their recent contributions might fit in a top-N page.
const query = `repo:${owner}/${repo} ${typeQuery} author:${creator}`;
const result = await github.rest.search.issuesAndPullRequests({
q: query,
sort: 'created',
order: 'asc',
per_page: 1,
});
// If their earliest match isn't this one, they've contributed before.
const earliest = result.data.items[0];
const hasPrior = !!earliest && earliest.number < number;
if (!hasPrior) {
const issueMsg = `Hey @${creator}, thanks for raising this. I really appreciate it.\n\nFair Code exists because bias in AI has real consequences for real people, so every issue matters here, whether it's a bug, a dataset question, or something that just didn't feel right. We'll take a look and get back to you.\n\nIn the meantime, feel free to explore the [live audits](https://www.thefaircode.xyz) or check the [contributing guide](CONTRIBUTING.md) if you want to dig deeper.`;
const prMsg = `Hey @${creator}, your first PR on Fair Code, that's awesome, thank you.\n\nThis project is about making AI more accountable, and contributions like yours are what keep that work going. We'll review your changes shortly.\n\nIf you haven't already, give the [contributing guide](CONTRIBUTING.md) a quick read: it covers how audits are structured and what we look for in a review.`;
await github.rest.issues.createComment({
owner,
repo,
issue_number: number,
body: isPR ? prMsg : issueMsg
});
}