Skip to content

Commit 6509906

Browse files
sicoyleyaron2
andauthored
chore: add standard dapr comm and repo cfg files (#138)
Signed-off-by: Samantha Coyle <[email protected]> Co-authored-by: Yaron Schneider <[email protected]>
1 parent cee485f commit 6509906

File tree

5 files changed

+248
-0
lines changed

5 files changed

+248
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
name: New Content Needed
3+
about: Template for requesting new documentation content
4+
title: "[Content] "
5+
labels: content/missing-information
6+
assignees: ''
7+
---
8+
9+
## Related Issue
10+
<!-- Link to the original issue that triggered this content request -->
11+
Related to: #<issue_number>
12+
13+
## Content Type
14+
<!-- What type of content is needed? -->
15+
- [ ] New feature documentation
16+
- [ ] API reference
17+
- [ ] How-to guide
18+
- [ ] Tutorial
19+
- [ ] Conceptual documentation
20+
- [ ] Other (please specify)
21+
22+
## Target Audience
23+
<!-- Who is this content for? -->
24+
- [ ] Developers
25+
- [ ] Operators
26+
- [ ] Architects
27+
- [ ] End users
28+
- [ ] Other (please specify)
29+
30+
## Content Description
31+
<!-- Provide a clear description of what content is needed -->
32+
<!-- What should the documentation cover? What are the key points to include? -->
33+
34+
## Additional Context
35+
<!-- Add any additional context about the content request here -->
36+
<!-- Include any specific requirements, examples, or references -->
37+
38+
## Acceptance Criteria
39+
<!-- What should be included in the documentation to consider it complete? -->
40+
- [ ]
41+
- [ ]
42+
- [ ]
43+
44+
## Resources
45+
<!-- Add any relevant resources, links, or references that might help with creating the content -->
46+
47+
## Notes
48+
<!-- Any additional notes or comments -->

.github/scripts/dapr_bot.js

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// List of owner who can control dapr-bot workflow
2+
// IMPORTANT: Make sure usernames are lower-cased
3+
const owners = [
4+
'yaron2',
5+
'cyb3rward0g'
6+
]
7+
8+
const docsIssueBodyTpl = (
9+
issueNumber
10+
) => `This issue was automatically created by \
11+
[Dapr Bot](https://github.com/dapr/dapr-agents/blob/master/.github/workflows/dapr-bot.yml) because a \"docs-needed\" label \
12+
was added to dapr/dapr#${issueNumber}. \n\n\
13+
TODO: Add more details as per [this template](.github/ISSUE_TEMPLATE/new-content-needed.md).`
14+
15+
module.exports = async ({ github, context }) => {
16+
if (
17+
context.eventName == 'issue_comment' &&
18+
context.payload.action == 'created'
19+
) {
20+
await handleIssueCommentCreate({ github, context })
21+
} else if (
22+
context.eventName == 'issues' &&
23+
context.payload.action == 'labeled'
24+
) {
25+
await handleIssueLabeled({ github, context })
26+
} else {
27+
console.log(`[main] event ${context.eventName} not supported, exiting.`)
28+
}
29+
}
30+
31+
/**
32+
* Handle issue comment create event.
33+
*/
34+
async function handleIssueCommentCreate({ github, context }) {
35+
const payload = context.payload
36+
const issue = context.issue
37+
const username = context.actor.toLowerCase()
38+
const isFromPulls = !!payload.issue.pull_request
39+
const commentBody = ((payload.comment.body || '') + '').trim()
40+
console.log(` Issue(owner/repo/number): ${issue.owner}/${issue.repo}/${issue.number}
41+
Actor(current username / id): ${username} / ${payload.comment.user.id}
42+
CommentID: ${payload.comment.id}
43+
CreatedAt: ${payload.comment.created_at}`
44+
)
45+
46+
if (!commentBody || !commentBody.startsWith('/')) {
47+
// Not a command
48+
return
49+
}
50+
51+
const commandParts = commentBody.split(/\s+/)
52+
const command = commandParts.shift()
53+
console.log(` Command: ${command}`)
54+
55+
// Commands that can be executed by anyone.
56+
if (command == '/assign') {
57+
await cmdAssign(github, issue, username, isFromPulls)
58+
return
59+
}
60+
61+
// Commands that can only be executed by owners.
62+
if (!owners.includes(username)) {
63+
console.log(
64+
`[handleIssueCommentCreate] user ${username} is not an owner, exiting.`
65+
)
66+
await commentUserNotAllowed(github, issue, username)
67+
return
68+
}
69+
70+
switch (command) {
71+
case '/make-me-laugh':
72+
await cmdMakeMeLaugh(github, issue)
73+
break
74+
// TODO: add more in future. Ref: https://github.com/dapr/dapr/blob/master/.github/scripts/dapr_bot.js#L99
75+
default:
76+
console.log(
77+
`[handleIssueCommentCreate] command ${command} not found, exiting.`
78+
)
79+
break
80+
}
81+
}
82+
83+
/**
84+
* Handle issue labeled event.
85+
*/
86+
async function handleIssueLabeled({ github, context }) {
87+
const payload = context.payload
88+
const label = payload.label.name
89+
const issueNumber = payload.issue.number
90+
91+
// This should not run in forks.
92+
if (context.repo.owner !== 'dapr') {
93+
console.log('[handleIssueLabeled] not running in dapr repo, exiting.')
94+
return
95+
}
96+
97+
// Authorization is not required here because it's triggered by an issue label event.
98+
// Only authorized users can add labels to issues.
99+
if (label == 'docs-needed') {
100+
// Open a new issue
101+
await github.rest.issues.create({
102+
owner: 'dapr',
103+
repo: 'docs',
104+
title: `New content needed for dapr/dapr#${issueNumber}`,
105+
labels: ['content/missing-information', 'created-by/dapr-bot'],
106+
body: docsIssueBodyTpl(issueNumber),
107+
})
108+
} else {
109+
console.log(
110+
`[handleIssueLabeled] label ${label} not supported, exiting.`
111+
)
112+
}
113+
}
114+
115+
/**
116+
* Assign the issue to the user who commented.
117+
* @param {*} github GitHub object reference
118+
* @param {*} issue GitHub issue object
119+
* @param {string} username GitHub user who commented
120+
* @param {boolean} isFromPulls is the workflow triggered by a pull request?
121+
*/
122+
async function cmdAssign(github, issue, username, isFromPulls) {
123+
if (isFromPulls) {
124+
console.log(
125+
'[cmdAssign] pull requests unsupported, skipping command execution.'
126+
)
127+
return
128+
} else if (issue.assignees && issue.assignees.length !== 0) {
129+
console.log(
130+
'[cmdAssign] issue already has assignees, skipping command execution.'
131+
)
132+
return
133+
}
134+
135+
await github.rest.issues.addAssignees({
136+
owner: issue.owner,
137+
repo: issue.repo,
138+
issue_number: issue.number,
139+
assignees: [username],
140+
})
141+
}
142+
143+
/**
144+
* Comment a funny joke.
145+
* @param {*} github GitHub object reference
146+
* @param {*} issue GitHub issue object
147+
*/
148+
async function cmdMakeMeLaugh(github, issue) {
149+
const result = await github.request(
150+
'https://official-joke-api.appspot.com/random_joke'
151+
)
152+
jokedata = result.data
153+
joke = 'I have a bad feeling about this.'
154+
if (jokedata && jokedata.setup && jokedata.punchline) {
155+
joke = `${jokedata.setup} - ${jokedata.punchline}`
156+
}
157+
158+
await github.rest.issues.createComment({
159+
owner: issue.owner,
160+
repo: issue.repo,
161+
issue_number: issue.number,
162+
body: joke,
163+
})
164+
}
165+
166+
/**
167+
* Sends a comment when the user who tried triggering the bot action is not allowed to do so.
168+
* @param {*} github GitHub object reference
169+
* @param {*} issue GitHub issue object
170+
* @param {string} username GitHub user who commented
171+
*/
172+
async function commentUserNotAllowed(github, issue, username) {
173+
await github.rest.issues.createComment({
174+
owner: issue.owner,
175+
repo: issue.repo,
176+
issue_number: issue.number,
177+
body: `👋 @${username}, my apologies but I can't perform this action for you because your username is not in the allowlist in the file ${'`.github/scripts/dapr_bot.js`'}.`,
178+
})
179+
}

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These owners are the maintainers and approvers of this repo
2+
# TODO: we need official teams in dapr github https://github.com/orgs/dapr/teams
3+
* @yaron2 @Cyb3rWard0g

GOVERNANCE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Governance
2+
3+
## Project Maintainers
4+
[Project maintainers](https://github.com/dapr/community/blob/master/MAINTAINERS.md) are responsible for activities around maintaining and updating Dapr. Final decisions on the project reside with the project maintainers.
5+
6+
Maintainers MUST remain active. If they are unresponsive for >3 months, they will be automatically removed unless a [super-majority](https://en.wikipedia.org/wiki/Supermajority#Two-thirds_vote) of the other project maintainers agrees to extend the period to be greater than 3 months.
7+
8+
New maintainers can be added to the project by a [super-majority](https://en.wikipedia.org/wiki/Supermajority#Two-thirds_vote) vote of the existing maintainers. A potential maintainer may be nominated by an existing maintainer. A vote is conducted in private between the current maintainers over the course of a one week voting period. At the end of the week, votes are counted and a pull request is made on the repo adding the new maintainer to the [CODEOWNERS](CODEOWNERS) file.
9+
10+
A maintainer may step down by submitting an [issue](https://github.com/dapr/dapr-agents/issues/new) stating their intent.
11+
12+
Changes to this governance document require a pull request with approval from a [super-majority](https://en.wikipedia.org/wiki/Supermajority#Two-thirds_vote) of the current maintainers.
13+
14+
## Code of Conduct
15+
This project has adopted the [Contributor Covenant Code of Conduct](https://github.com/dapr/community/blob/master/CODE-OF-CONDUCT.md)

SECURITY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Security Policy
2+
3+
https://docs.dapr.io/operations/support/support-security-issues/

0 commit comments

Comments
 (0)