Skip to content
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 providers #76

Merged
merged 12 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions packages/plugin-github/src/plugins/createCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import {
isCreateCommitContent,
} from "../types";
import { commitAndPushChanges, getRepoPath, writeFiles } from "../utils";
import { sourceCodeProvider } from "../providers/sourceCode";
import { testFilesProvider } from "../providers/testFiles";
import { workflowFilesProvider } from "../providers/workflowFiles";
import { documentationFilesProvider } from "../providers/documentationFiles";
import { releasesProvider } from "../providers/releases";

export const createCommitAction: Action = {
name: "CREATE_COMMIT",
Expand Down Expand Up @@ -195,10 +200,16 @@ export const createCommitAction: Action = {
};

export const githubCreateCommitPlugin: Plugin = {
name: "githubCreateCommitPlugin",
name: "githubCreateCommit",
description:
"Integration with GitHub for commiting changes to the repository",
"Integration with GitHub for committing changes to the repository",
actions: [createCommitAction],
evaluators: [],
providers: [],
providers: [
sourceCodeProvider,
testFilesProvider,
workflowFilesProvider,
documentationFilesProvider,
releasesProvider,
],
};
13 changes: 12 additions & 1 deletion packages/plugin-github/src/plugins/createMemoriesFromFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import {
isCreateMemoriesFromFilesContent,
} from "../types";
import { getRepoPath, retrieveFiles } from "../utils";
import { sourceCodeProvider } from "../providers/sourceCode";
import { testFilesProvider } from "../providers/testFiles";
import { workflowFilesProvider } from "../providers/workflowFiles";
import { documentationFilesProvider } from "../providers/documentationFiles";
import { releasesProvider } from "../providers/releases";

export async function addFilesToMemory(
runtime: IAgentRuntime,
Expand Down Expand Up @@ -320,5 +325,11 @@ export const githubCreateMemorizeFromFilesPlugin: Plugin = {
description: "Integration with GitHub for creating memories from files",
actions: [createMemoriesFromFilesAction],
evaluators: [],
providers: [],
providers: [
sourceCodeProvider,
testFilesProvider,
workflowFilesProvider,
documentationFilesProvider,
releasesProvider,
],
};
13 changes: 12 additions & 1 deletion packages/plugin-github/src/plugins/createPullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import {
getRepoPath,
writeFiles,
} from "../utils";
import { sourceCodeProvider } from "../providers/sourceCode";
import { testFilesProvider } from "../providers/testFiles";
import { workflowFilesProvider } from "../providers/workflowFiles";
import { documentationFilesProvider } from "../providers/documentationFiles";
import { releasesProvider } from "../providers/releases";

export const createPullRequestAction: Action = {
name: "CREATE_PULL_REQUEST",
Expand Down Expand Up @@ -242,5 +247,11 @@ export const githubCreatePullRequestPlugin: Plugin = {
description: "Integration with GitHub for creating a pull request",
actions: [createPullRequestAction],
evaluators: [],
providers: [],
providers: [
sourceCodeProvider,
testFilesProvider,
workflowFilesProvider,
documentationFilesProvider,
releasesProvider,
],
};
13 changes: 12 additions & 1 deletion packages/plugin-github/src/plugins/initializeRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import {
createReposDirectory,
getRepoPath,
} from "../utils";
import { sourceCodeProvider } from "../providers/sourceCode";
import { testFilesProvider } from "../providers/testFiles";
import { workflowFilesProvider } from "../providers/workflowFiles";
import { documentationFilesProvider } from "../providers/documentationFiles";
import { releasesProvider } from "../providers/releases";

export const initializeRepositoryAction: Action = {
name: "INITIALIZE_REPOSITORY",
Expand Down Expand Up @@ -252,5 +257,11 @@ export const githubInitializePlugin: Plugin = {
description: "Integration with GitHub for initializing the repository",
actions: [initializeRepositoryAction],
evaluators: [],
providers: [],
providers: [
sourceCodeProvider,
testFilesProvider,
workflowFilesProvider,
documentationFilesProvider,
releasesProvider,
],
};
51 changes: 51 additions & 0 deletions packages/plugin-github/src/providers/documentationFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { elizaLogger, IAgentRuntime, Memory, Provider } from "@ai16z/eliza";
import { GitHubService } from "../services/github";

export const documentationFilesProvider: Provider = {
get: async (runtime: IAgentRuntime, message: Memory) => {
try {
// Extract repository details from state
const state = await runtime.composeState(message);
const owner = state?.owner as string;
const repo = state?.repo as string;

if (!owner || !repo) {
elizaLogger.warn("Missing repository details in state");
return { files: [], repository: null };
}

// Initialize GitHub service
const githubService = new GitHubService({
auth: runtime.getSetting("GITHUB_API_TOKEN"),
owner,
repo,
});

// Get all documentation files
const docFiles = await githubService.getDocumentation();

// Get contents for each documentation file
const docContents = await Promise.all(
docFiles.map(async (path) => {
const content = await githubService.getFileContents(path);
return { path: path, content };
})
);

elizaLogger.info(
`Retrieved ${docContents.length} documentation files from ${owner}/${repo}`
);

return {
files: docContents,
repository: {
owner,
repo,
},
};
} catch (error) {
elizaLogger.error("Error in documentationFilesProvider:", error);
return { files: [], repository: null };
}
},
};
43 changes: 43 additions & 0 deletions packages/plugin-github/src/providers/releases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { elizaLogger, IAgentRuntime, Memory, Provider } from "@ai16z/eliza";
import { GitHubService } from "../services/github";

export const releasesProvider: Provider = {
get: async (runtime: IAgentRuntime, message: Memory) => {
try {
// Extract repository details from state
const state = await runtime.composeState(message);
const owner = state?.owner as string;
const repo = state?.repo as string;

if (!owner || !repo) {
elizaLogger.warn("Missing repository details in state");
return { releases: [], repository: null };
}

// Initialize GitHub service
const githubService = new GitHubService({
auth: runtime.getSetting("GITHUB_API_TOKEN"),
owner,
repo,
});

// Get all releases
const releases = await githubService.getReleases();

elizaLogger.info(
`Retrieved ${releases.length} releases from ${owner}/${repo}`
);

return {
releases,
repository: {
owner,
repo,
},
};
} catch (error) {
elizaLogger.error("Error in releasesProvider:", error);
return { releases: [], repository: null };
}
},
};
51 changes: 51 additions & 0 deletions packages/plugin-github/src/providers/sourceCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { elizaLogger, IAgentRuntime, Memory, Provider } from "@ai16z/eliza";
import { GitHubService } from "../services/github";

export const sourceCodeProvider: Provider = {
get: async (runtime: IAgentRuntime, message: Memory) => {
try {
// Extract repository details from state
const state = await runtime.composeState(message);
const owner = state?.owner as string;
const repo = state?.repo as string;

if (!owner || !repo) {
elizaLogger.warn("Missing repository details in state");
return { files: [], content: {} };
}

// Initialize GitHub service
const githubService = new GitHubService({
auth: runtime.getSetting("GITHUB_API_TOKEN"),
owner,
repo,
});

// Get all source file paths
const filePaths = await githubService.getSourceFiles("");

// Get contents for each file
const fileContents = await Promise.all(
filePaths.map(async (path) => {
const content = await githubService.getFileContents(path);
return { path, content };
})
);

elizaLogger.info(
`Retrieved ${fileContents.length} files from ${owner}/${repo}`
);

return {
files: fileContents,
repository: {
owner,
repo,
},
};
} catch (error) {
elizaLogger.error("Error in sourceCodeProvider:", error);
return { files: [], repository: null };
}
},
};
52 changes: 52 additions & 0 deletions packages/plugin-github/src/providers/testFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { elizaLogger, IAgentRuntime, Memory, Provider } from "@ai16z/eliza";
import { GitHubService } from "../services/github";

export const testFilesProvider: Provider = {
get: async (runtime: IAgentRuntime, message: Memory) => {
try {
// Extract repository details from state
const state = await runtime.composeState(message);
const owner = state?.owner as string;
const repo = state?.repo as string;
const testPath = (state?.testPath as string) || ""; // Optional test directory path

if (!owner || !repo) {
elizaLogger.warn("Missing repository details in state");
return { files: [], content: {} };
}

// Initialize GitHub service
const githubService = new GitHubService({
auth: runtime.getSetting("GITHUB_API_TOKEN"),
owner,
repo,
});

// Get test files paths
const testFilePaths = await githubService.getTestFiles(testPath);

// Get contents for each test file
const testFiles = await Promise.all(
testFilePaths.map(async (path) => {
const content = await githubService.getFileContents(path);
return { path, content };
})
);

elizaLogger.info(
`Retrieved ${testFiles.length} test files from ${owner}/${repo}`
);

return {
files: testFiles,
repository: {
owner,
repo,
},
};
} catch (error) {
elizaLogger.error("Error in testFilesProvider:", error);
return { files: [], repository: null };
}
},
};
53 changes: 53 additions & 0 deletions packages/plugin-github/src/providers/workflowFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { elizaLogger, IAgentRuntime, Memory, Provider } from "@ai16z/eliza";
import { GitHubService } from "../services/github";

export const workflowFilesProvider: Provider = {
get: async (runtime: IAgentRuntime, message: Memory) => {
try {
// Extract repository details from state
const state = await runtime.composeState(message);
const owner = state?.owner as string;
const repo = state?.repo as string;

if (!owner || !repo) {
elizaLogger.warn("Missing repository details in state");
return { files: [], repository: null };
}

// Initialize GitHub service
const githubService = new GitHubService({
auth: runtime.getSetting("GITHUB_API_TOKEN"),
owner,
repo,
});

// Get all workflow files
const workflows = await githubService.getWorkflows();

// Get contents for each workflow file
const workflowContents = await Promise.all(
workflows.map(async (workflow) => {
const content = await githubService.getFileContents(
workflow.path
);
return { path: workflow.path, content };
})
);

elizaLogger.info(
`Retrieved ${workflowContents.length} workflow files from ${owner}/${repo}`
);

return {
files: workflowContents,
repository: {
owner,
repo,
},
};
} catch (error) {
elizaLogger.error("Error in workflowFilesProvider:", error);
return { files: [], repository: null };
}
},
};
Loading
Loading