forked from elizaOS/eliza
-
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
feat: add github create and modify issue and add comment to issue act… #96
Merged
monilpat
merged 4 commits into
feat/add-github-providers
from
feat/add-github-issue-actions
Dec 12, 2024
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
547120b
feat: add github create and modify issue and add comment to issue act…
snobbee 272a162
refactor: update ModifyIssueSchema to make title and body optional in…
snobbee 529105b
Merge branch 'sif-dev' into feat/add-github-issue-actions
snobbee b0fc8c9
Merge branch 'feat/add-github-providers' into feat/add-github-issue-a…
snobbee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
packages/plugin-github/src/plugins/addCommentToIssue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { | ||
composeContext, | ||
elizaLogger, | ||
generateObjectV2, | ||
Action, | ||
HandlerCallback, | ||
IAgentRuntime, | ||
Memory, | ||
ModelClass, | ||
Plugin, | ||
State, | ||
} from "@ai16z/eliza"; | ||
import { GitHubService } from "../services/github"; | ||
import { | ||
AddCommentToIssueContent, | ||
AddCommentToIssueSchema, | ||
isAddCommentToIssueContent, | ||
} from "../types"; | ||
import { addCommentToIssueTemplate } from "../templates"; | ||
|
||
export const addCommentToIssueAction: Action = { | ||
name: "ADD_COMMENT_TO_ISSUE", | ||
similes: [ | ||
"ADD_COMMENT_TO_ISSUE", | ||
"COMMENT_ON_ISSUE", | ||
"POST_COMMENT", | ||
"ADD_COMMENT", | ||
], | ||
description: "Adds a comment to an existing issue in the GitHub repository", | ||
validate: async (runtime: IAgentRuntime) => { | ||
const token = !!runtime.getSetting("GITHUB_API_TOKEN"); | ||
return token; | ||
}, | ||
handler: async ( | ||
runtime: IAgentRuntime, | ||
message: Memory, | ||
state: State, | ||
options: any, | ||
callback: HandlerCallback | ||
) => { | ||
elizaLogger.log("Composing state for message:", message); | ||
if (!state) { | ||
state = (await runtime.composeState(message)) as State; | ||
} else { | ||
state = await runtime.updateRecentMessageState(state); | ||
} | ||
|
||
const context = composeContext({ | ||
state, | ||
template: addCommentToIssueTemplate, | ||
}); | ||
|
||
const details = await generateObjectV2({ | ||
runtime, | ||
context, | ||
modelClass: ModelClass.SMALL, | ||
schema: AddCommentToIssueSchema, | ||
}); | ||
|
||
if (!isAddCommentToIssueContent(details.object)) { | ||
elizaLogger.error("Invalid content:", details.object); | ||
throw new Error("Invalid content"); | ||
} | ||
|
||
const content = details.object as AddCommentToIssueContent; | ||
|
||
elizaLogger.info("Adding comment to issue in the repository..."); | ||
|
||
const githubService = new GitHubService({ | ||
owner: content.owner, | ||
repo: content.repo, | ||
auth: runtime.getSetting("GITHUB_API_TOKEN"), | ||
}); | ||
|
||
try { | ||
const comment = await githubService.addIssueComment( | ||
content.issue, | ||
content.comment | ||
); | ||
|
||
elizaLogger.info( | ||
`Added comment to issue #${content.issue} successfully!` | ||
); | ||
|
||
callback({ | ||
text: `Added comment to issue #${content.issue} successfully!`, | ||
attachments: [], | ||
}); | ||
} catch (error) { | ||
elizaLogger.error( | ||
`Error adding comment to issue #${content.issue} in repository ${content.owner}/${content.repo}:`, | ||
error | ||
); | ||
callback( | ||
{ | ||
text: `Error adding comment to issue #${content.issue}. Please try again.`, | ||
}, | ||
[] | ||
); | ||
} | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "Add a comment to issue #1 in repository user1/repo1: 'This is fixed in the latest release'", | ||
}, | ||
}, | ||
{ | ||
user: "{{agentName}}", | ||
content: { | ||
text: "Added comment to issue #1 successfully!", | ||
action: "ADD_COMMENT", | ||
}, | ||
}, | ||
], | ||
], | ||
}; | ||
|
||
export const githubAddCommentToIssuePlugin: Plugin = { | ||
name: "githubAddCommentToIssue", | ||
description: "Integration with GitHub for adding comments to issues", | ||
actions: [addCommentToIssueAction], | ||
evaluators: [], | ||
providers: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { | ||
composeContext, | ||
elizaLogger, | ||
generateObjectV2, | ||
Action, | ||
HandlerCallback, | ||
IAgentRuntime, | ||
Memory, | ||
ModelClass, | ||
Plugin, | ||
State, | ||
} from "@ai16z/eliza"; | ||
import { GitHubService } from "../services/github"; | ||
import { createIssueTemplate } from "../templates"; | ||
import { | ||
CreateIssueContent, | ||
CreateIssueSchema, | ||
isCreateIssueContent, | ||
} from "../types"; | ||
|
||
export const createIssueAction: Action = { | ||
name: "CREATE_ISSUE", | ||
similes: ["CREATE_ISSUE", "GITHUB_CREATE_ISSUE", "OPEN_ISSUE"], | ||
description: "Creates a new issue in the GitHub repository", | ||
validate: async (runtime: IAgentRuntime) => { | ||
const token = !!runtime.getSetting("GITHUB_API_TOKEN"); | ||
return token; | ||
}, | ||
handler: async ( | ||
runtime: IAgentRuntime, | ||
message: Memory, | ||
state: State, | ||
options: any, | ||
callback: HandlerCallback | ||
) => { | ||
elizaLogger.log("Composing state for message:", message); | ||
if (!state) { | ||
state = (await runtime.composeState(message)) as State; | ||
} else { | ||
state = await runtime.updateRecentMessageState(state); | ||
} | ||
|
||
const context = composeContext({ | ||
state, | ||
template: createIssueTemplate, | ||
}); | ||
|
||
const details = await generateObjectV2({ | ||
runtime, | ||
context, | ||
modelClass: ModelClass.SMALL, | ||
schema: CreateIssueSchema, | ||
}); | ||
|
||
if (!isCreateIssueContent(details.object)) { | ||
elizaLogger.error("Invalid content:", details.object); | ||
throw new Error("Invalid content"); | ||
} | ||
|
||
const content = details.object as CreateIssueContent; | ||
|
||
elizaLogger.info("Creating issue in the repository..."); | ||
|
||
const githubService = new GitHubService({ | ||
owner: content.owner, | ||
repo: content.repo, | ||
auth: runtime.getSetting("GITHUB_API_TOKEN"), | ||
}); | ||
|
||
try { | ||
const issue = await githubService.createIssue( | ||
content.title, | ||
content.body, | ||
content.labels | ||
); | ||
|
||
elizaLogger.info( | ||
`Created issue successfully! Issue number: ${issue.number}` | ||
); | ||
|
||
callback({ | ||
text: `Created issue #${issue.number} successfully!`, | ||
attachments: [], | ||
}); | ||
} catch (error) { | ||
elizaLogger.error( | ||
`Error creating issue in repository ${content.owner}/${content.repo}:`, | ||
error | ||
); | ||
callback( | ||
{ | ||
text: `Error creating issue in repository ${content.owner}/${content.repo}. Please try again.`, | ||
}, | ||
[] | ||
); | ||
} | ||
}, | ||
examples: [ | ||
[ | ||
{ | ||
user: "{{user1}}", | ||
content: { | ||
text: "Create an issue in repository user1/repo1 titled 'Bug: Application crashes on startup'", | ||
}, | ||
}, | ||
{ | ||
user: "{{agentName}}", | ||
content: { | ||
text: "Created issue #1 successfully!", | ||
action: "CREATE_ISSUE", | ||
}, | ||
}, | ||
], | ||
], | ||
}; | ||
|
||
export const githubCreateIssuePlugin: Plugin = { | ||
name: "githubCreateIssue", | ||
description: "Integration with GitHub for creating issues in repositories", | ||
actions: [createIssueAction], | ||
evaluators: [], | ||
providers: [], | ||
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. same here should be list of recent issues but not blocking |
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We probably want to add a provider that shows all the comments for an issue can be a follow up not urgent