|
| 1 | + |
| 2 | +import type {CreatePullRequestOptions } from "./IGitManager.js" |
| 3 | +import dotenv from "dotenv"; |
| 4 | +import * as git from "simple-git"; |
| 5 | +import type { PrModeFileChange, Repository } from "./types/index.js"; |
| 6 | + |
| 7 | +dotenv.config(); |
| 8 | + |
| 9 | +/** |
| 10 | + * Manages operations related to interacting with a Git repository using the GitHub API. |
| 11 | + */ |
| 12 | +export class LocalGitManager { |
| 13 | + git: git.SimpleGit; |
| 14 | + |
| 15 | + |
| 16 | + /** |
| 17 | + * Constructor for a class that initializes the Octokit instance with the provided Repository and checks if the GITHUB_ACCESS_TOKEN is set in the environment. |
| 18 | + * @param {Repository} repository - The repository instance to use |
| 19 | + * @throws {Error} Throws an error if the GITHUB_ACCESS_TOKEN is not set |
| 20 | + */ |
| 21 | + constructor(public repository: Repository) { |
| 22 | + |
| 23 | + this.git = git.simpleGit(); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Retrieve files in a specific pull request. |
| 28 | + * @param {number} pullNumber - The number of the pull request to get files from. |
| 29 | + * @returns {Promise<PrModeFileChange[]>} - Array of objects representing file changes in the pull request. |
| 30 | + */ |
| 31 | + public async getFilesInPullRequest( |
| 32 | + pullNumber: number |
| 33 | + ): Promise<PrModeFileChange[]> { |
| 34 | + const log = await this.git.log({ |
| 35 | + //from: "main", |
| 36 | + // to: `origin/pull/${pullNumber}/head`, |
| 37 | + maxCount: 100, |
| 38 | + }); |
| 39 | + |
| 40 | + console.log(log); |
| 41 | + return [] |
| 42 | +// // return data.map((file: any) => ({ |
| 43 | +// filename: file.filename, |
| 44 | +// status: file.status, |
| 45 | +// additions: file.additions, |
| 46 | +// deletions: file.deletions, |
| 47 | +// changes: file.changes, |
| 48 | +// contents_url: file.contents_url, |
| 49 | +// })); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Creates a new branch in the GitHub repository using the given branch name and base branch. |
| 54 | + * |
| 55 | + * @param {string} branchName - The name of the new branch to be created. |
| 56 | + * @param {string} baseBranch - The name of the branch to base the new branch off of. |
| 57 | + * @returns {Promise<void>} - A Promise that resolves when the branch is successfully created. |
| 58 | + */ |
| 59 | + public async createBranch( |
| 60 | + branchName: string, |
| 61 | + baseBranch: string |
| 62 | + ): Promise<void> { |
| 63 | + |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Asynchronously commits a file to a repository using the GitHub API. |
| 68 | + * |
| 69 | + * @param {string} branchName - The name of the branch to commit the file to. |
| 70 | + * @param {string} filePath - The path of the file to commit. |
| 71 | + * @param {string} content - The content of the file to commit. |
| 72 | + * @param {string} message - The commit message. |
| 73 | + * @returns {Promise<void>} A promise that resolves when the file is successfully committed. |
| 74 | + */ |
| 75 | + public async commitFile( |
| 76 | + branchName: string, |
| 77 | + filePath: string, |
| 78 | + content: string, |
| 79 | + message: string |
| 80 | + ): Promise<void> { |
| 81 | + |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Create a pull request using the provided options. |
| 86 | + * @param {CreatePullRequestOptions} options - The options for creating the pull request. |
| 87 | + * @returns {Promise<void>} A Promise that resolves once the pull request is successfully created. |
| 88 | + */ |
| 89 | + public async createPullRequest( |
| 90 | + options: CreatePullRequestOptions |
| 91 | + ): Promise<void> { |
| 92 | + |
| 93 | + } |
| 94 | +} |
0 commit comments