Code Monkey home page Code Monkey logo

llmgit's Introduction

LLMGit

Use llm to talk to git

build & run tests

from the root directory run

.devcontainer/post_create.sh
poetry install
poetry shell
poetry run pytest --disable-warnings

install new packages

poetry add pack
git add poetry.lock pyproject.toml && git commit "installed new pkg" 
git push origin

llmgit's People

Contributors

aminehd avatar pooriyapfn avatar

Stargazers

Cam avatar

Watchers

 avatar Kostas Georgiou avatar  avatar

llmgit's Issues

Setup github cli and create classes

import subprocess
import json
from typing import List, Optional
from pydantic import BaseModel, validator
from urllib.parse: urlparse

class Commit(BaseModel):
hash: str
author: str
message: str
date: str

class Repository(BaseModel):
url: str
name: str = ""
owner: str = ""
commits: List[Commit] = []

@validator('url')
def parse_url(cls, value):
    parsed_url = urlparse(value)
    path_parts = parsed_url.path.strip('/').split('/')
    if len(path_parts) != 2:
        raise ValueError("Invalid GitHub repository URL")
    cls.owner, cls.name = path_parts
    return value

def fetch_commits(self):
    try:
        result = subprocess.run(
            ["gh", "repo", "view", f"{self.owner}/{self.name}", "--json", "commits", "--limit", "100"],
            capture_output=True,
            text=True,
            check=True
        )
        data = json.loads(result.stdout)
        self.commits = [
            Commit(
                hash=commit['oid'],
                author=commit['author']['user']['login'] if commit['author']['user'] else 'Unknown',
                message=commit['messageHeadline'],
                date=commit['committedDate']
            ) for commit in data['commits']
        ]
    except subprocess.CalledProcessError as e:
        print(f"Error fetching commits: {e}")

def get_commit_by_hash(self, commit_hash: str) -> Optional[Commit]:
    for commit in self.commits:
        if commit.hash == commit_hash:
            return commit
    return None

Example usage

if name == "main":
repo_url = "https://github.com/user/example-repo"
repo = Repository(url=repo_url)

# Fetch commits using GitHub CLI
repo.fetch_commits()

# Retrieve a commit by its hash
commit = repo.get_commit_by_hash("abc123")
if commit:
    print(commit)
else:
    print("Commit not found")

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.