Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions nodecg-io-github/extension/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { NodeCG } from "nodecg-types/types/server";
import { Result, emptySuccess, success, ServiceBundle } from "nodecg-io-core";
import { Octokit } from "@octokit/rest";

export interface GitHubConfig {
token: string;
}

export type GitHubClient = Octokit;

module.exports = (nodecg: NodeCG) => {
new GitHubService(nodecg, "github", __dirname, "../schema.json").register();
};

class GitHubService extends ServiceBundle<GitHubConfig, GitHubClient> {
async validateConfig(config: GitHubConfig): Promise<Result<void>> {
const octokit = new Octokit({
auth: config.token,
});
await octokit.repos.listForAuthenticatedUser({
page: 0,
per_page: 1,
});
return emptySuccess();
}

async createClient(config: GitHubConfig): Promise<Result<GitHubClient>> {
const client = new Octokit({
auth: config.token,
});
this.nodecg.log.info("Successfully created github client.");
return success(client);
}

stopClient(_: GitHubClient): void {
//
}

removeHandlers(_: GitHubClient): void {
//
}
}
47 changes: 47 additions & 0 deletions nodecg-io-github/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "nodecg-io-github",
"version": "0.2.0",
"description": "Allows to connect to the GitHub REST API",
"homepage": "https://nodecg.io/RELEASE/samples/github",
"author": {
"name": "noeppi_noeppi",
"url": "https://github.com/noeppi-noeppi"
},
"repository": {
"type": "git",
"url": "https://github.com/codeoverflow-org/nodecg-io.git",
"directory": "nodecg-io-github"
},
"files": [
"**/*.js",
"**/*.js.map",
"**/*.d.ts",
"*.json"
],
"main": "extension/index",
"scripts": {
"build": "tsc -b",
"watch": "tsc -b -w",
"clean": "tsc -b --clean"
},
"keywords": [
"nodecg-io",
"nodecg-bundle"
],
"nodecg": {
"compatibleRange": "^1.1.1",
"bundleDependencies": {
"nodecg-io-core": "^0.2.0"
}
},
"license": "MIT",
"devDependencies": {
"@types/node": "^15.0.2",
"nodecg-types": "^1.8.2",
"typescript": "^4.2.4"
},
"dependencies": {
"nodecg-io-core": "^0.2.0",
"@octokit/rest": "^18.12.0"
}
}
12 changes: 12 additions & 0 deletions nodecg-io-github/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"properties": {
"token": {
"type": "string",
"description": "The GitHub API token."
}
},
"required": ["token"]
}
3 changes: 3 additions & 0 deletions nodecg-io-github/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../tsconfig.common.json"
}
Loading