Skip to content

Commit

Permalink
Merge pull request #16 from tracehubpm/empty
Browse files Browse the repository at this point in the history
feat(#15): comment.ts
  • Loading branch information
h1alexbel committed Mar 9, 2024
2 parents 7370e71 + 466de4f commit 56d6626
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 11 deletions.
43 changes: 43 additions & 0 deletions dist/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Comment = void 0;
/**
* Comment.
*/
class Comment {
/**
* Ctor.
* @param github Github
* @param issue Issue
* @param text Text
*/
constructor(github, issue, text) {
this.github = github;
this.issue = issue;
this.text = text;
}
/**
* Post a comment.
*/
post() {
return __awaiter(this, void 0, void 0, function* () {
yield this.github.issues.createComment({
owner: this.issue.owner,
repo: this.issue.repo,
issue_number: this.issue.number,
body: this.text
});
});
}
;
}
exports.Comment = Comment;
69 changes: 66 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 4761:
/***/ (function(__unused_webpack_module, exports) {

"use strict";

var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Comment = void 0;
/**
* Comment.
*/
class Comment {
/**
* Ctor.
* @param github Github
* @param issue Issue
* @param text Text
*/
constructor(github, issue, text) {
this.github = github;
this.issue = issue;
this.text = text;
}
/**
* Post a comment.
*/
post() {
return __awaiter(this, void 0, void 0, function* () {
yield this.github.issues.createComment({
owner: this.issue.owner,
repo: this.issue.repo,
issue_number: this.issue.number,
body: this.text
});
});
}
;
}
exports.Comment = Comment;


/***/ }),

/***/ 9324:
/***/ (function(__unused_webpack_module, exports) {

Expand Down Expand Up @@ -116,6 +167,7 @@ exports.github = void 0;
const core = __importStar(__nccwpck_require__(2186));
const rest_1 = __nccwpck_require__(5375);
const issue_body_1 = __nccwpck_require__(9324);
const comment_1 = __nccwpck_require__(4761);
if (process.env.GITHUB_ACTIONS) {
exports.github = __nccwpck_require__(5438);
}
Expand All @@ -125,7 +177,10 @@ else {
issue: {
owner: "test",
repo: "test",
number: 123
number: 123,
user: {
login: "test"
}
}
}
};
Expand All @@ -136,10 +191,18 @@ function run() {
try {
const issue = exports.github.context.issue;
if (issue) {
console.log(`Found new issue: ${issue.number}`);
const body = yield new issue_body_1.IssueBody(new rest_1.Octokit({ auth: core.getInput("github_token") }), issue).fetch();
console.log(`Found new issue: #${issue.number}`);
const octokit = new rest_1.Octokit({ auth: core.getInput("github_token") });
const body = yield new issue_body_1.IssueBody(octokit, issue).fetch();
console.log(`body: ${body}`);
// quality analysis.
if (!body) {
yield new comment_1.Comment(octokit, issue, `
@${issue.user.login} the issue body is empty.
Please provide more details.
`).post();
console.log(`Comment posted to the #${issue.number}`);
}
}
else {
console.log("No opened issue found");
Expand Down
18 changes: 15 additions & 3 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ exports.github = void 0;
const core = __importStar(require("@actions/core"));
const rest_1 = require("@octokit/rest");
const issue_body_1 = require("./issue-body");
const comment_1 = require("./comment");
if (process.env.GITHUB_ACTIONS) {
exports.github = require("@actions/github");
}
Expand All @@ -68,7 +69,10 @@ else {
issue: {
owner: "test",
repo: "test",
number: 123
number: 123,
user: {
login: "test"
}
}
}
};
Expand All @@ -79,10 +83,18 @@ function run() {
try {
const issue = exports.github.context.issue;
if (issue) {
console.log(`Found new issue: ${issue.number}`);
const body = yield new issue_body_1.IssueBody(new rest_1.Octokit({ auth: core.getInput("github_token") }), issue).fetch();
console.log(`Found new issue: #${issue.number}`);
const octokit = new rest_1.Octokit({ auth: core.getInput("github_token") });
const body = yield new issue_body_1.IssueBody(octokit, issue).fetch();
console.log(`body: ${body}`);
// quality analysis.
if (!body) {
yield new comment_1.Comment(octokit, issue, `
@${issue.user.login} the issue body is empty.
Please provide more details.
`).post();
console.log(`Comment posted to the #${issue.number}`);
}
}
else {
console.log("No opened issue found");
Expand Down
87 changes: 87 additions & 0 deletions src/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023-2024 Tracehub.git
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import {Octokit} from "@octokit/rest";

/**
* Comment.
*/
export class Comment {

/**
* Github.
*/
private readonly github: Octokit;

/**
* Issue.
*/
private readonly issue: {
owner: string,
repo: string,
number: number,
user: {
login: string
}
};

/**
* Text to post.
*/
private readonly text: string;

/**
* Ctor.
* @param github Github
* @param issue Issue
* @param text Text
*/
constructor(
github: Octokit,
issue: {
owner: string,
repo: string,
number: number,
user: {
login: string
}
},
text: string
) {
this.github = github;
this.issue = issue;
this.text = text;
}

/**
* Post a comment.
*/
async post() {
await this.github.issues.createComment({
owner: this.issue.owner,
repo: this.issue.repo,
issue_number: this.issue.number,
body: this.text
});
};
}
30 changes: 25 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import * as core from "@actions/core";
import {Octokit} from "@octokit/rest";
import {IssueBody} from "./issue-body";
import {Comment} from "./comment";

export let github: {
context: {
issue: {
owner: string,
repo: string,
number: number
user: {
login: string
}
}
}
};
Expand All @@ -42,7 +46,10 @@ if (process.env.GITHUB_ACTIONS) {
issue: {
owner: "test",
repo: "test",
number: 123
number: 123,
user: {
login: "test"
}
}
}
};
Expand All @@ -53,16 +60,29 @@ async function run() {
try {
const issue = github.context.issue;
if (issue) {
console.log(`Found new issue: ${issue.number}`);
console.log(`Found new issue: #${issue.number}`);
const octokit = new Octokit(
{auth: core.getInput("github_token")}
);
const body = await new IssueBody(
new Octokit(
{auth: core.getInput("github_token")}
),
octokit,
issue
).fetch();
console.log(`body: ${body}`);
// quality analysis.

if (!body) {
await new Comment(
octokit,
issue,
`
@${issue.user.login} the issue body is empty.
Please provide more details.
`
).post();
console.log(`Comment posted to the #${issue.number}`);
}

} else {
console.log("No opened issue found");
}
Expand Down

0 comments on commit 56d6626

Please sign in to comment.