-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QA 2 #4
base: development
Are you sure you want to change the base?
QA 2 #4
Changes from all commits
b13ab8a
30396e8
255adec
edcccd3
b59a754
7ed9b96
d63f64a
a84e69c
6b0e649
c1cea68
b23877e
ca8773d
4cedae5
e5caa73
26dbe85
2d3cdc1
5ffedbe
db0c53f
d7819c4
19fc446
7e17049
83e72fe
b2e672a
05dda18
d27dc72
047e550
c4c544a
0c0caf2
21ae8a9
972f52d
650bf41
9397438
5dc0cae
68527bc
94ce85e
bb7c0e2
458b093
1399c69
519b9b4
db764c8
d05fb81
7436032
cd9df0a
9c6f719
f3173b7
d57a968
9315a95
f7cba36
ef10010
50c3a99
fc33279
2053f51
3a02caa
df4442b
39728a0
e22e798
76d4ede
35be950
e077e27
0b6666a
1ec8023
c886b79
053c4ea
b08d7de
75e2d78
63e85e0
adf5a7e
41760f0
dc389fc
91ed08f
b084d27
900ae2e
c315c1b
4fa0e55
da2cc9d
617ef43
fb0671b
984c514
524807b
a6ee757
37cdc03
4e48186
7c6ea0b
91bcde2
616f5bc
96f88d1
7368a20
1aae776
ab41864
fe46897
06d2bdc
29a9dd1
7ee70e2
4fc18bd
c7489d3
ff18936
403444a
907d6a0
32cda98
aded7a6
df2696b
bc89c84
6834472
8b760a7
b0b32a8
ef22145
cfa02a5
11afdeb
94a406d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins: | ||
- uses: | ||
- plugin: https://damaged-alysa-moniswap-b2f3cc8b.koyeb.app | ||
with: | ||
disabledCommands: [] | ||
miscellaneous: | ||
maxConcurrentTasks: 3 | ||
runsOn: ["issue_comment", "issue_comment.created", "issue_comment.edited"] |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,4 @@ | ||||||
name: "the name of the plugin" | ||||||
name: "ubiquity-contribs-scanner" | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
on: | ||||||
workflow_dispatch: | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,6 @@ cypress/screenshots | |
script.ts | ||
.wrangler | ||
test-dashboard.md | ||
.platform* | ||
*Dockerfile* | ||
.dockerignore |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
import { Context } from "../types"; | ||
|
||
export async function scanContributions(context: Context) { | ||
const { logger, payload, octokit } = context; | ||
|
||
const store: Record<string, Record<string, number>> = {}; | ||
|
||
const repo = payload.repository.name; | ||
const issueNumber = payload.issue.number; | ||
const owner = payload.repository.owner.login; | ||
const body = payload.comment.body; | ||
|
||
if (!body.match(/scanContributions/i)) { | ||
return; | ||
} | ||
|
||
logger.info("Scanning Events!"); | ||
|
||
try { | ||
const contributors = await octokit.repos.listContributors({ | ||
repo, | ||
owner, | ||
}); | ||
|
||
contributors.data.forEach((contributor) => { | ||
if (contributor.login) { | ||
store[contributor.login] = {}; | ||
} | ||
}); | ||
|
||
const issueTimelineEvents = await octokit.paginate(octokit.issues.listEventsForTimeline, { owner, repo, issue_number: issueNumber }); | ||
const issueEvents = await octokit.paginate(octokit.issues.listEvents, { owner, repo, issue_number: issueNumber }); | ||
const issueReactionEvents = await octokit.paginate(octokit.reactions.listForIssue, { owner, repo, issue_number: issueNumber }); | ||
const issueCommentEvents = await octokit.paginate(octokit.issues.listComments, { owner, repo, issue_number: issueNumber }); | ||
|
||
issueTimelineEvents.forEach((ev) => { | ||
if ("actor" in ev && ev.actor && !store[ev.actor.login]) { | ||
store[ev.actor.login] = {}; | ||
} | ||
|
||
if ("actor" in ev && ev.actor) { | ||
const key = (payload.issue.pull_request ? "pull_request." : "issues.").concat(ev.event); | ||
if (!store[ev.actor.login][key]) store[ev.actor.login][key] = 1; | ||
else store[ev.actor.login][key] += 1; | ||
} | ||
}); | ||
|
||
issueEvents.forEach((ev) => { | ||
if (ev.actor && !store[ev.actor.login]) { | ||
store[ev.actor.login] = {}; | ||
} | ||
|
||
if (ev.actor && !issueTimelineEvents.map((te) => te.event).includes(ev.event)) { | ||
const key = (payload.issue.pull_request ? "pull_request." : "issues.").concat(ev.event); | ||
if (!store[ev.actor.login][key]) store[ev.actor.login][key] = 1; | ||
else store[ev.actor.login][key] += 1; | ||
} | ||
}); | ||
|
||
issueReactionEvents.forEach((ev) => { | ||
if (ev.user && !store[ev.user.login]) { | ||
store[ev.user.login] = {}; | ||
} | ||
if (ev.user) { | ||
if (!store[ev.user.login][ev.content]) store[ev.user.login][ev.content] = 1; | ||
else store[ev.user.login][ev.content] += 1; | ||
} | ||
}); | ||
|
||
for (const issueCommentEvent of issueCommentEvents) { | ||
const reactions = await octokit.paginate(octokit.reactions.listForIssueComment, { owner, repo, comment_id: issueCommentEvent.id }); | ||
|
||
reactions.forEach((reaction) => { | ||
if (reaction.user && !store[reaction.user.login]) { | ||
store[reaction.user.login] = {}; | ||
} | ||
|
||
if (reaction.user) { | ||
if (!store[reaction.user.login][reaction.content]) store[reaction.user.login][reaction.content] = 1; | ||
else store[reaction.user.login][reaction.content] += 1; | ||
} | ||
}); | ||
} | ||
|
||
if (payload.issue.pull_request) { | ||
const pullReviews = await octokit.paginate(octokit.pulls.listReviews, { owner, repo, pull_number: issueNumber }); | ||
const pullReviewComments = await octokit.paginate(octokit.pulls.listReviewComments, { owner, repo, pull_number: issueNumber }); | ||
|
||
for (const pullReview of pullReviews) { | ||
if (pullReview.user && !store[pullReview.user.login]) { | ||
store[pullReview.user.login] = {}; | ||
} | ||
|
||
if (pullReview.user) { | ||
const key = "pull_request_review.".concat(pullReview.state.toLowerCase()); | ||
if (!store[pullReview.user.login][key]) store[pullReview.user.login][key] = 1; | ||
else store[pullReview.user.login][key] += 1; | ||
} | ||
} | ||
|
||
for (const pullReviewComment of pullReviewComments) { | ||
if (pullReviewComment.user && !store[pullReviewComment.user.login]) { | ||
store[pullReviewComment.user.login] = {}; | ||
} | ||
|
||
const key = "pull_request_review_comment.created"; | ||
|
||
if (pullReviewComment.user) { | ||
if (!store[pullReviewComment.user.login][key]) store[pullReviewComment.user.login][key] = 1; | ||
else store[pullReviewComment.user.login][key] += 1; | ||
} | ||
|
||
const reactions = await octokit.paginate(octokit.reactions.listForPullRequestReviewComment, { owner, repo, comment_id: pullReviewComment.id }); | ||
|
||
reactions.forEach((reaction) => { | ||
if (reaction.user && !store[reaction.user.login]) { | ||
store[reaction.user.login] = {}; | ||
} | ||
|
||
if (reaction.user) { | ||
if (!store[reaction.user.login][reaction.content]) store[reaction.user.login][reaction.content] = 1; | ||
else store[reaction.user.login][reaction.content] += 1; | ||
} | ||
}); | ||
} | ||
} | ||
|
||
logger.info("Contributions stats: ", store); | ||
const octokitCommentBody = "```json\n" + JSON.stringify(store, undefined, 2) + "\n```"; | ||
|
||
await octokit.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
body: octokitCommentBody, | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
const octokitCommentBody = | ||
"An error occurred while scanning this repository\n ```json\n" + JSON.stringify({ error: error, stack: error.stack }, undefined, 2) + "\n```"; | ||
await octokit.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
body: octokitCommentBody, | ||
}); | ||
logger.error(`Error creating comment:`, { error: error, stack: error.stack }); | ||
throw error; | ||
} else { | ||
const octokitCommentBody = | ||
"An error occurred while scanning this repository\n ```json\n" + JSON.stringify({ err: error, error: new Error() }, undefined, 2) + "\n```"; | ||
await octokit.issues.createComment({ | ||
owner, | ||
repo, | ||
issue_number: issueNumber, | ||
body: octokitCommentBody, | ||
}); | ||
logger.error(`Error creating comment:`, { err: error, error: new Error() }); | ||
throw error; | ||
} | ||
} | ||
|
||
logger.ok(`Successfully scanned contributions!`, { repo, issueNumber }); | ||
logger.verbose(`Exiting scanContributions`); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
import * as github from "@actions/github"; | ||
import { Octokit } from "@octokit/rest"; | ||
import { TransformDecodeCheckError, TransformDecodeError, Value, ValueError } from "@sinclair/typebox/value"; | ||
import { Env, envSchema, envValidator, PluginSettings, pluginSettingsSchema, pluginSettingsValidator } from "../types"; | ||
import { Context, Env, envSchema, envValidator, PluginSettings, pluginSettingsSchema, pluginSettingsValidator } from "../types"; | ||
|
||
export async function returnDataToKernel(repoToken: string, stateId: string, output: object, eventType = "return-data-to-ubiquity-os-kernel") { | ||
export async function returnDataToKernel( | ||
repoToken: string, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is obsolete and would be handled by the SDK. |
||
stateId: string, | ||
output: object, | ||
context: Context, | ||
eventType = "return-data-to-ubiquity-os-kernel" | ||
) { | ||
const octokit = new Octokit({ auth: repoToken }); | ||
return octokit.repos.createDispatchEvent({ | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
owner: context.payload.repository.owner.login, | ||
repo: context.payload.repository.name, | ||
event_type: eventType, | ||
client_payload: { | ||
state_id: stateId, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { Logs } from "@ubiquity-dao/ubiquibot-logger"; | |
* | ||
* ubiquity:listeners: ["issue_comment.created", ...] | ||
*/ | ||
export type SupportedEventsU = "issue_comment.created" | "issue_comment.deleted" | "issue_comment.edited"; | ||
export type SupportedEventsU = "issue_comment.created" | "issue_comment.edited"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to listen to these events but rather issue closed. |
||
|
||
export type SupportedEvents = { | ||
[K in SupportedEventsU]: K extends WebhookEventName ? WebhookEvent<K> : never; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ export const pluginSettingsSchema = T.Object( | |
configurableResponse: T.String(), | ||
customStringsUrl: T.Optional(T.String()), | ||
}, | ||
{ default: { configurableResponse: "Hello, world!" } } | ||
{ default: { configurableResponse: "This is the UbiquityOS contributions scanner." } } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be removed. |
||
); | ||
|
||
export const pluginSettingsValidator = new StandardValidator(pluginSettingsSchema); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be deleted.