Coder Social home page Coder Social logo

deltachat-github-bot's Introduction

DC-Github-Bot

A Deltachat-bot which works as bridge between Deltachat and Github Webhoooks

Usage

Users can interact with the bot by issuing commands. All commands have to be prefixed with gh and can be of the following form:

enum Cli {
    /// Subscribe to an event
    Subscribe {
        /// Id of the repository
        repo: usize,

        Pr {
            #[arg(value_enum)]
            pr_action: PRAction,
        },
        Issue {
            #[arg(value_enum)]
            issue_action: IssueAction,
        },
    },

    /// Unsubscribe from an event
    Unsubscribe {
        /// Id of the repository
        repo: usize,

        Pr {
            #[arg(value_enum)]
            pr_action: PRAction,
        },

        Issue {
            #[arg(value_enum)]
            issue_action: IssueAction,
        },
    },

    // Change and list supported repositories
    Repositories {
        // List all available repositories
        List,

        // Add a webhook for a new repository
        Add {
            // Name of repo owner (user or organisation)
            owner: String,

            // Name of repository
            repository: String,

            // REST-Api key
            api_key: String,
        },

        // Remove a repositories webhook
        Remove {
            // Id of repository to remove
            repository: usize,

            // REST-Api key
            api_key: String,
        },
    },
}

Examples

Adding a repository:

gh repositories add septias github-bot ghp_xyp

where ghp_xyp is a github rest-api-key that can be created like this.

Adding an event listener:

gh subscribe 123534 issue opened

where 123534 is a valid repo taken from:

Listing all repositories:

gh repositories list

Architecture

  • The bot has to be hosted under a public IP to be able to receive github webhooks.
  • The file server.rs spins up a tide webserver listening on port 0.0.0.0:8080/receive
  • The repository webhook sends all events to this endpoint where they are parsed and processed.
  • After receiving a webhook event, the bot distributes it to all listeners.
  • The client requests are parsed using clap.

Files

.
├── src
│ ├── bot.rs       // bot code
│ ├── db.rs        // surrealdb-api
│ ├── main.rs      // spin up bot
│ ├── parser.rs    // CLI definition using `clap`
│ ├── queries      // some of the sql-queries used in `db.rs`
│ ├── rest_api.rs  // interaction with the github rest-api
│ ├── server.rs    // spin up `tide` server
│ ├── shared.rs    // some types
│ └── utils.rs

Development

Start the bot like this:

RUST_LOG=info addr=<add> mail_pw=<pw> cargo r

where <addr> and <pw> are some valid login credentials for an email-server.

Testing

It comes in handy to send webhook-events manually with curl:

curl -X POST --data "mock/issue_open.json" localhost:8080/receive --header "X-GitHub-Event: issues"

Further improvement

  • Don't allow users to register listeners twice
    • this gets rejected internally, but is not shown to user

deltachat-github-bot's People

Contributors

septias avatar

Watchers

 avatar

Forkers

brabo

deltachat-github-bot's Issues

cargo run fails due to missing or private dependency repo

$ addr=[email protected] mail_pw=sekrit cargo run
Updating git repository https://github.com/deltachat/deltachat-core-rust
Updating crates.io index
Updating git repository https://github.com/async-email/async-imap
Updating git repository https://github.com/dignifiedquire/rs-async-zip
Updating git repository https://github.com/deltachat/rust-email
Updating git repository https://github.com/async-email/encoded-words
Updating git repository https://github.com/deltachat/lettre
Updating git repository https://github.com/Majored/rs-async-io-utilities
error: failed to get async_io_utilities as a dependency of package async_zip v0.0.8 (https://github.com/dignifiedquire/rs-async-zip?branch=main#5556c5ac)
... which satisfies git dependency async_zip (locked to 0.0.8) of package deltachat v1.98.0 (https://github.com/deltachat/deltachat-core-rust?tag=1.98.0#b6b2f453)
... which satisfies git dependency deltachat (locked to 1.98.0) of package github-bot v0.1.0 (/home/ghbot/github-bot)

Caused by:
failed to load source for dependency async_io_utilities

Caused by:
Unable to update https://github.com/Majored/rs-async-io-utilities#85de4cfc

Caused by:
failed to clone into: /home/ghbot/.cargo/git/db/rs-async-io-utilities-5b754873e3909201

Caused by:
failed to authenticate when downloading repository

  • attempted to find username/password via git's credential.helper support, but failed

if the git CLI succeeds then net.git-fetch-with-cli may help here
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
failed to acquire username/password from local configuration

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.