Rand Stats

JSON::RepositoryEvent

zef:lizmat

Actions Status Actions Status Actions Status

NAME

JSON::RepositoryEvent - representation of a repository event

SYNOPSIS

use JSON::RepositoryEvent;
my $io = "foo.json".IO;

# create from incoming request
my $new = JSON::RepositoryEvent.new(%data, request);
$io.spurt(to-json($new));

# create from existing file
my $saved = JSON::RepositoryEvent.new($io.slurp);

DESCRIPTION

The JSON::RepositoryEvent provides a distribution for mapping repository related events in JSON format (such as typically provided by collaborative services such as GitHub / Codeberg in a webhook) into Raku classes with an object oriented interface.

All classes can be instantiated with the .new method and providing a correctly structured Map (or Hash). This is specifically needed when processing JSON-files that have been previously saved with the JSON::Webhook module.

CREATION FROM A WEBHOOK

The JSON::RepositoryEvent object can (also) be created using the information that is available inside a Cro::HTTP::Router route.

# create from incoming request
my $new = JSON::RepositoryEvent.new(%data, request);

The first argument is the data structure (usually a Map or a Hash, the second argument is the Cro::HTTP::Request object which contains all of the information needed.

Using the JSON::Webhook this can be as simple as:

sub processor(\data, \request) {
    JSON::RepositoryEvent.new(data, request)
}
JSON::Webhook.new(:&processor);

JSON::RepositoryEvent

The JSON::RepositoryEvent class wraps the data from a request in the payload accessor: this then contains an instances of any of the other JSON::RepositoryEvent::xxx classes.

METHODS

STATUS

This is still very much in alpha state. Quite a number of payloads from GitHub have been implemented, not so many from Forgejo yet. Help in implementing this is very much welcomed.

NAMING LOGIC

The data structures in the GitHub and Forgejo (e.g. Codeberg) API's typically use underscores in their names. No underscores are used in the Raku classes. If a name is mapped to a class, then an underscore created camelcase class names. So "pull_request" becomes PullRequest as a class name. Other fields that have an underscore map the underscores to hyphens, so "created_at" as the name of a field in the data structure, becomes "created-at" as an accessor (method name).

Some exceptions: field names that start with an underscore are used verbatim in method names (as methods starting with a hyphen are illegal in Raku). If a field name starts with +, it is replaced by the string "plus" in the method name. If a field name starts with -, it is replaces by the string "minus" in the method name.

THEORY OF OPERATION

The underlying data structure is always a Map (or a Hash). All classes are subclasses of Map, so all the functionality that you can expect from a Map can be used on any of the classes in this distribution.

All classes could be considered to be "views" on the underlying data structure: all "accessors" are in fact accessing certain parts of that data structure by key. This approach allows for fast loading: only actual parts of the data structure that need to be accessed, will be fetched on demand.

GITHUB EVENT CLASSES

The full name of these classes is JSON::RepositoryEvent::GitHub::Eventxxx. The JSON::RepositoryEvent part is not mentioned here in the documentation for convenience.

GitHub::EventCheckRun

GitHub::EventCheckSuite

GitHub::EventCommitComment

GitHub::EventDelete

GitHub::EventFork

GitHub::EventGollum

GitHub::EventIssueComment

GitHub::EventIssues

GitHub::EventLabel

GitHub::EventPing

GitHub::EventPublic

GitHub::EventPullRequest

GitHub::EventPullRequestComment

GitHub::EventPullRequestReview

EventPullRequestReviewComment

EventPullRequestReviewThread

GitHub::EventPush

GitHub::EventRelease

GitHub::EventRepository

GitHub::EventStar

GitHub::EventStatus

GitHub::EventWatch

GitHub::EventWorkflowJob

GitHub::EventWorkflowRun

GITHUB CLASSES

These classes represent (common) parts of the actual payload classes for GitHub events. The JSON::RepositoryEvent part is not mentioned here in the documentation for convenience.

GitHub::Actor

GitHub::App

GitHub::Asset

GitHub::CheckRun

GitHub::CheckSuite

GitHub::Comment

GitHub::Commit

GitHub::DependenciesSummary

GitHub::Hook

GitHub::HookConfig

GitHub::Issue

GitHub::Label

GitHub::License

GitHub::Organization

GitHub::Output

GitHub::Page

Description of a change made to a page in the wiki.

GitHub::Permissions

GitHub::Person

GitHub::PullRequest

GitHub::PullRequestComment

PullRequestCommentThread

GitHub::PushCommit

GitHub::Reactions

GitHub::Review

GitHub::Release

GitHub::Repository

GitHub::Response

GitHub::State

GitHub::SubIssuesSummary

GitHub::Tree

GitHub::TreeCommit

GitHub::Verification

GitHub::Workflow

GitHub::WorkflowJob

GitHub::WorkflowRun

FORGEJO EVENTS CLASSES

The full name of these classes is JSON::RepositoryEvent::Forgejo::Eventxxx. The JSON::RepositoryEvent part is not mentioned here in the documentation for convenience.

Forgejo::EventCreate

Forgejo::EventDelete

Forgejo::EventFork

Forgejo::EventIssueComment

Forgejo::EventIssues

Forgejo::EventPullRequest

Forgejo::EventPullRequestComment

Forgejo::EventPush

FORGEJO CLASSES

These classes represent (common) parts of the actual payload classes for Forgejo (Codeberg) events. The JSON::RepositoryEvent part is not mentioned here in the documentation for convenience.

Forgejo::Actor

Forgejo::Commit

Forgejo::Issue

Forgejo::Permissions

Forgejo::Person

Forgejo::PullRequest

Forgejo::Repository

Forgejo::State

Forgejo::Tracker

AUTHOR

Elizabeth Mattijsen liz@raku.rocks

COPYRIGHT AND LICENSE

Copyright 2026 Elizabeth Mattijsen

Source can be located at: https://codeberg.org/lizmat/JSON-RepositoryEvent . Comments and Pull Requests are welcome.

If you like this module, or what I'm doing more generally, committing to a small sponsorship would mean a great deal to me!

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.