deep_auto_git
v1.0.0
Published
`deep_auto_git` is a powerful Node.js package designed to simplify and automate common Git operations across various Git providers like GitHub and GitLab. It provides a unified interface for interacting with different Git services, making it easier to man
Readme
deep_auto_git
deep_auto_git is a powerful Node.js package designed to simplify and automate common Git operations across various Git providers like GitHub and GitLab. It provides a unified interface for interacting with different Git services, making it easier to manage repositories programmatically.
Features
- Unified Git Operations: Perform common Git actions (clone, pull, push, commit) through a consistent API.
- Provider Agnostic: Supports multiple Git providers with an extensible architecture.
- Utility Functions: Includes helpful utilities for tasks like generating unique branch names and parsing repository URLs.
Installation
To install deep_auto_git, use npm:
npm install deep_auto_gitUsage
GitProvider (Base Class)
The GitProvider class provides the core Git operations. It can be extended to support specific Git providers.
const { GitProvider } = require('deep_auto_git');
async function basicGitOperations() {
const git = new GitProvider(); // No specific config needed for basic operations
const repoUrl = 'YOUR_REPO_URL'; // e.g., 'https://github.com/user/repo.git'
const destinationPath = './my-repo';
try {
console.log('Cloning repository...');
await git.clone(repoUrl, destinationPath);
console.log('Repository cloned.');
// Change directory to the cloned repository
process.chdir(destinationPath);
console.log('Pulling latest changes...');
await git.pull('.');
console.log('Latest changes pulled.');
// Example: Make some changes and commit
// fs.writeFileSync('newfile.txt', 'Hello, world!');
// await git.commit('.', 'Add newfile.txt');
// console.log('Changes committed.');
// console.log('Pushing changes...');
// await git.push('.', 'main'); // Replace 'main' with your branch name
// console.log('Changes pushed.');
} catch (error) {
console.error('Git operation failed:', error);
}
}
basicGitOperations();GithubProvider
Extend GitProvider for GitHub-specific functionalities. You would typically initialize this with a GitHub API client.
const { GithubProvider } = require('deep_auto_git');
class MyGithubProvider extends GithubProvider {
constructor(config) {
super(config);
// Initialize GitHub specific API client here
// e.g., this.githubApi = new Octokit({ auth: config.token });
}
async getPullRequests(repoOwner, repoName) {
// Example: Implement GitHub specific API call
// const response = await this.githubApi.pulls.list({ owner: repoOwner, repo: repoName });
// return response.data;
console.log(`Getting pull requests for ${repoOwner}/${repoName} on GitHub.`);
return [];
}
}
// Example Usage (requires actual GitHub API integration)
// const githubConfig = { token: 'YOUR_GITHUB_TOKEN' };
// const github = new MyGithubProvider(githubConfig);
// github.getPullRequests('octocat', 'Spoon-Knife').then(prs => console.log(prs));GitlabProvider
Extend GitProvider for GitLab-specific functionalities. You would typically initialize this with a GitLab API client.
const { GitlabProvider } = require('deep_auto_git');
class MyGitlabProvider extends GitlabProvider {
constructor(config) {
super(config);
// Initialize GitLab specific API client here
// e.g., this.gitlabApi = new Gitlab({ host: config.host, token: config.token });
}
async getMergeRequests(projectId) {
// Example: Implement GitLab specific API call
// const response = await this.gitlabApi.MergeRequests.all(projectId);
// return response;
console.log(`Getting merge requests for project ID ${projectId} on GitLab.`);
return [];
}
}
// Example Usage (requires actual GitLab API integration)
// const gitlabConfig = { host: 'https://gitlab.com', token: 'YOUR_GITLAB_TOKEN' };
// const gitlab = new MyGitlabProvider(gitlabConfig);
// gitlab.getMergeRequests(12345).then(mrs => console.log(mrs));Utility Functions
deep_auto_git provides several utility functions to assist with common tasks.
generateUniqueBranchName(prefix)
Generates a unique branch name using a given prefix and a timestamp.
const { generateUniqueBranchName } = require('deep_auto_git');
const branchName = generateUniqueBranchName('feature');
console.log(`Generated branch name: ${branchName}`); // e.g., feature-1678886400000parseRepoUrl(repoUrl)
Parses a repository URL to extract provider and repository details.
const { parseRepoUrl } = require('deep_auto_git');
const githubRepoUrl = 'https://github.com/octocat/Spoon-Knife.git';
const gitlabRepoUrl = 'https://gitlab.com/gitlab-org/gitlab-foss.git';
const unknownRepoUrl = 'https://example.com/my/repo.git';
console.log(parseRepoUrl(githubRepoUrl));
// Output: { provider: 'github', owner: 'octocat', repo: 'Spoon-Knife' }
console.log(parseRepoUrl(gitlabRepoUrl));
// Output: { provider: 'gitlab', owner: 'gitlab-org', repo: 'gitlab-foss' }
console.log(parseRepoUrl(unknownRepoUrl));
// Output: { provider: 'unknown', url: 'https://example.com/my/repo.git' }Extensibility
The modular design of deep_auto_git allows for easy extension to support additional Git providers or custom functionalities. Simply extend the GitProvider class and implement the necessary methods.
Automated Release Management
This project uses semantic-release for fully automated version management and package publishing. Releases are triggered automatically based on commit messages following the Conventional Commits specification. This ensures consistent versioning and simplifies the release process.
Testing
To run tests, execute:
npm testContributing
We welcome contributions! Please see our CONTRIBUTING.md for details on how to get started.
