Coder Social home page Coder Social logo

gitfailguard's Introduction

GitFailGuard

GitFailGuard is an advanced AI-powered tool designed to streamline your development workflow by automatically reviewing failed GitHub Actions and generating detailed GitHub Issues. This enables you to quickly identify and address problems, ensuring a more efficient development process.

Key Features:

  • CI/CD Failure AI Analysis: GitFailGuard reviews failed GitHub Actions and creates comprehensive GitHub Issues, providing clear insights and actionable steps to resolve issues.
  • Github Issue AI Question Assistant: Mention @GitFailGuard in any GitHub issue comment, and GitFailGuard will respond to your questions, offering assistance and guidance directly within your repository.
  • CI/CD Log Analysis in Pull Requests using CodeRabit AI: GitFailGuard can post logs from failed actions directly into your pull requests, facilitating thorough reviews from CodeRabbit with @coderabbitai pings and ensuring code quality.

With GitFailGuard, you can enhance your CI/CD pipeline, improve code review processes, and maintain high standards of code quality effortlessly.

Sequence-Diagram

Features

  • Automated detection of failed GitHub Actions.
  • AI-powered log analysis to identify potential causes of failure.
  • Automatic creation of GitHub Issues with detailed failure information.
  • Assistant feature to respond to questions in GitHub issue comments when mentioned with @GitFailGuard.
  • Interaction with CodeRabbit with @coderabbitai pings to enable log reviews inside of pull requests.

Example

Setup

Prerequisites

  • Docker and Docker Compose
  • GitHub token with appropriate permissions
  • OpenAI API key

Environment Variables

Ensure you have the following environment variables set:

  • GITHUB_TOKEN: Your GitHub token.
  • OPENAI_API_KEY: Your OpenAI API key.
  • ENABLE_CODERABBIT: (Optional) Enables CodeRabbit reviews in pull requests.

You can set these variables in your shell:

export GITHUB_TOKEN=your_github_token_here
export OPENAI_API_KEY=your_openai_api_key_here

# # only set if you want to enable coderabit PR comments to failure logs
# # do not set env var if you do not have coderabit enabled
# export ENABLE_CODERABBIT="true"

Local Testing

View our guide on how to test GitFailGuard locally for developers looking to contribute and fork this project.

Production Deployment

You can deploy a production app using docker-compose or kubernetes.

Then follow our guide on Connecting your github repos to GitFailGuard.

This application can be deployed using any platform that supports Docker containers, such as Digital Ocean, AWS, Azure, or Google Cloud. Ensure you set the environment variables in the deployment environment as described in the setup section.

Other Notes

Project Structure

GitFailGuard/
├── .github/
│   └── workflows/
│       └── deploy.yml
├── src/
│   ├── __init__.py
│   ├── main.py
│   ├── webhook_handler.py
│   ├── log_analyzer.py
│   ├── github_issue_creator.py
├── tests/
│   ├── __init__.py
│   ├── test_webhook_handler.py
│   ├── test_log_analyzer.py
│   ├── test_github_issue_creator.py
├── requirements.txt
├── README.md
├── .env.example
├── setup.py
├── Dockerfile
└── docker-compose.yml

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the Apache License. See the LICENSE file for more details.

Acknowledgments


If you like what we do support us on Patreon!

Come join the Discord

Feel free to reach out if you have any questions or need further assistance.

gitfailguard's People

Contributors

cohenaj194 avatar

Stargazers

 avatar

Watchers

 avatar

gitfailguard's Issues

GitFailGuard: Black 1716667795

The GitHub Action Black failed.

Logs: View Logs

Analysis:
Based on the logs provided, the failure seems to be related to a code formatting issue. The message "1 file would be reformatted, 9 files would be left unchanged" indicates that there was an attempt to reformat a file but it failed. The error message "Process completed with exit code 1" further confirms that the reformatting process failed.

To fix this issue, you can try the following steps:

  1. Check the code formatting tool being used and ensure it is properly configured.
  2. Verify that the file being reformatted is not locked or in use by another process.
  3. Check for any syntax errors or issues in the file that may be causing the reformatting process to fail.
  4. Update the code formatting tool to the latest version to see if that resolves the issue.

By following these recommendations, you should be able to address the code formatting failure and successfully reformat the file.

GitFailGuard: Black 1716742503

The GitHub Action Black failed.

Logs: View Logs

Analysis:
Based on the logs provided, the failure seems to be related to the black code formatter. The error message "Oh no! � � �" indicates that there was an issue with the code formatting process.

To fix this issue, you can try the following steps:

  1. Check the configuration of the black code formatter to ensure it is set up correctly.
  2. Run the black code formatter with the --diff option to see the proposed changes before applying them.
  3. Make sure that the files being checked by black are valid Python files and are located in the correct directory.

By following these steps, you should be able to identify and resolve the issue with the black code formatter.

CodeRabbit has been notified to review the logs of this run.

GitFailGuard: Black 1716740978

The GitHub Action Black failed.

Logs: View Logs

Analysis:
Based on the logs provided, the failure seems to be related to a code formatting issue. The message "1 file would be reformatted, 9 files would be left unchanged" indicates that there was an attempt to reformat a file but it failed for some reason.

To fix this issue, you can try the following steps:

  1. Check the code formatting tool being used and ensure it is properly configured.
  2. Verify that the file being reformatted is not locked or in use by another process.
  3. Review the code changes that triggered the reformatting to identify any potential issues.
  4. Check for any specific error messages or warnings related to the code formatting process.

By following these steps, you should be able to identify the cause of the failure and take appropriate action to resolve it.

GitFailGuard: Black 1716590523

The GitHub Action Black failed.

Logs: View Logs

Analysis:
Cause of failure: The process completed with exit code 1, indicating an error occurred during the reformatting of files.

Recommendation for a fix:

  1. Check the logs for any specific error messages that may provide more information on what went wrong during the reformatting process.
  2. Verify that the reformatting tool being used is compatible with the files being reformatted.
  3. Ensure that the files being reformatted are not in use or locked by another process.
  4. Check for any syntax errors or issues in the files that may be causing the reformatting process to fail.
  5. Consider updating the reformatting tool to the latest version to see if any known issues have been fixed.

GitFailGuard: Black 1716590034

The GitHub Action Black failed.

Logs: View Logs

Analysis:
Cause of failure: The process completed with exit code 1, indicating an error occurred during the reformatting of files.

Recommendation for a fix:

  1. Check the logs for any specific error messages that may provide more information on what went wrong during the reformatting process.
  2. Ensure that the reformatting tool being used is compatible with the files being reformatted.
  3. Check for any syntax errors or issues in the files that may be causing the reformatting process to fail.
  4. Try running the reformatting process again after addressing any potential issues identified in the logs.

GitFailGuard: Black 1716741047

The GitHub Action Black failed.

Logs: View Logs

Analysis:
Based on the logs provided, the failure seems to be related to a code formatting issue. The message "1 file would be reformatted, 9 files would be left unchanged" indicates that there was an attempt to reformat a file, but it failed for some reason.

To fix this issue, you can try the following steps:

  1. Check the code formatting tool being used and ensure it is properly configured.
  2. Verify that the file being reformatted is not locked or in use by another process.
  3. Review the code changes that triggered the reformatting to identify any potential issues.
  4. Check for any specific error messages or warnings related to the code formatting process.

By following these steps, you should be able to identify the cause of the failure and take appropriate action to resolve it.

CodeRabbit has been notified to review the logs of this run.

save git log cleanup script

import os
import requests

def fetch_logs(repo_owner, repo_name, run_id, job_id):
    github_token = os.getenv('GITHUB_TOKEN')
    headers = {
        "Authorization": f"token {github_token}",
        "Accept": "application/vnd.github.v3+json"
    }
    
    url = f"https://api.github.com/repos/{repo_owner}/{repo_name}/actions/jobs/{job_id}/logs"
    
    response = requests.get(url, headers=headers)
    
    if response.status_code == 200:
        return response.text
    else:
        return f"Error: Unable to fetch logs, status code: {response.status_code}"


def extract_info_from_url(url):
    # Split the URL by '/'
    parts = url.split("/")
    
    # Extract repository owner, repository name, run ID, and job ID from the URL
    repo_owner = parts[3]
    repo_name = parts[4]
    run_id = parts[7]
    job_id = parts[9]
    
    return repo_owner, repo_name, run_id, job_id

def cleanup_logs(logs):
    # split by newline
    logs = logs.split("\n")
    # find the index of all lines containing ##[endgroup]
    endgroup_indices = [i for i, line in enumerate(logs) if "##[endgroup]" in line]
    # find the index of the line containing ##[error]
    error_index = [i for i, line in enumerate(logs) if "##[error]" in line]

    if len(error_index) == 0:
        return "No error found in logs"

    # get all logs between the last ##[endgroup] and the first ##[error] including he line with ##[error]
    cleaned_logs = logs[endgroup_indices[-1]:error_index[0]+1]
    return "\n".join(cleaned_logs)



def main():
    # Example usage
    url = "https://github.com/ff14-advanced-market-search/mysql-population/actions/runs/9216448689/job/25356749022"
    # url = "https://github.com/ff14-advanced-market-search/temp-fe/actions/runs/9066730415/job/24910289744"


    repo_owner, repo_name, run_id, job_id = extract_info_from_url(url)

    # # Example usage
    # repo_owner = "ff14-advanced-market-search"
    # repo_name = "mysql-population"
    # run_id = "9199994409"
    # job_id = "25305762140"

    logs = fetch_logs(repo_owner, repo_name, run_id, job_id)
    clean_logs = cleanup_logs(logs)


    if logs is not None:
        print(clean_logs)

if __name__ == "__main__":
    main()

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.