Skip to content

Commit

Permalink
style: add code styling
Browse files Browse the repository at this point in the history
  • Loading branch information
steveoh committed Oct 18, 2021
1 parent 2428ee0 commit 4b59f45
Show file tree
Hide file tree
Showing 9 changed files with 1,027 additions and 163 deletions.
18 changes: 0 additions & 18 deletions .eslintrc.json

This file was deleted.

5 changes: 5 additions & 0 deletions .ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
dist/
.github/
package.json
package-lock.json
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 GitHub Actions
Copyright (c) 2021 UGRC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ Use any form of `/remind me [what] [when]`, such as:
## Sample Usage

```yml
name: "check reminders"
name: 'check reminders'

on:
schedule:
- cron: "0 * * * *"
- cron: '0 * * * *'

jobs:
reminder:
Expand Down
34 changes: 17 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const core = require("@actions/core");
const github = require("@actions/github");
const core = require('@actions/core');
const github = require('@actions/github');
const {
getRemindersFromBody,
getPastDueReminders,
createCommentsMetadata,
markAsNotified,
} = require("./utilities");
} = require('./utilities');

const LABEL = "reminder";
const LABEL = 'reminder';

function getIssueProps(context) {
return {
Expand All @@ -19,39 +19,39 @@ function getIssueProps(context) {
async function run() {
try {
const context = github.context.payload;
const owner = core.getInput("repositoryOwner");
const repository = core.getInput("repository");
const owner = core.getInput('repositoryOwner');
const repository = core.getInput('repository');
const octokit = github.getOctokit(
core.getInput("repoToken", { required: true })
core.getInput('repoToken', { required: true })
);

context.repository = {
owner,
name: repository.split("/")[1],
name: repository.split('/')[1],
};

let issues = [];
core.startGroup("get open reminder issues");
core.startGroup('get open reminder issues');
for await (const response of octokit.paginate.iterator(
octokit.rest.issues.listForRepo,
{
...getIssueProps(context),
state: "open",
state: 'open',
labels: [LABEL],
}
)) {
issues = issues.concat(response.data);
}

if (issues.length < 1) {
core.info("no open issues found with the reminder label");
core.info('no open issues found with the reminder label');

return;
}
core.endGroup();

const reminders = [];
core.startGroup("get all reminders from issues");
core.startGroup('get all reminders from issues');
issues.forEach((issue) => {
const remindersFromIssue = getRemindersFromBody(issue.body);

Expand All @@ -69,23 +69,23 @@ async function run() {
});

if (reminders.length < 1) {
core.info("no reminders found");
core.info('no reminders found');

return;
}
core.endGroup();

core.startGroup("filter reminders for past due");
core.startGroup('filter reminders for past due');
const pastDueReminders = getPastDueReminders(Date.now(), reminders);

if (reminders.length < 1) {
core.info("no past due reminders found");
core.info('no past due reminders found');

return;
}
core.endGroup();

core.startGroup("notify past due reminders");
core.startGroup('notify past due reminders');
core.info(`sending ${reminders.length} past due notifications`);

const metadata = createCommentsMetadata(pastDueReminders);
Expand All @@ -99,7 +99,7 @@ async function run() {
}
core.endGroup();

core.startGroup("removing notification metadata");
core.startGroup('removing notification metadata');
for (let i = 0; i < pastDueReminders.length; i++) {
const { body, reminder, issueNumber } = pastDueReminders[i];

Expand Down
50 changes: 25 additions & 25 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,43 @@ const {
getPastDueReminders,
createCommentsMetadata,
markAsNotified,
} = require("./utilities");
} = require('./utilities');

describe("getRemindersFromBody", () => {
test("can find reminder issues", () => {
describe('getRemindersFromBody', () => {
test('can find reminder issues', () => {
const body = `testing
<!-- bot: {"reminders":[{"id":1,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"}]} -->`;

const expected = {
id: 1,
who: "stdavis",
what: "celebrate",
when: "2020-06-24T09:28:33.000Z",
who: 'stdavis',
what: 'celebrate',
when: '2020-06-24T09:28:33.000Z',
};

expect(getRemindersFromBody(body)).toEqual([expected]);
});
test("Can handle body being null", () => {
test('Can handle body being null', () => {
const body = null;
expect(getRemindersFromBody(body)).toEqual([]);
});
});

describe("getPastDueReminders", () => {
test("returns past due reminders", () => {
describe('getPastDueReminders', () => {
test('returns past due reminders', () => {
const today = new Date(2000, 1, 1);
const items = [
{
issueNumber: 1,
reminder: {
when: "2001-06-24T09:00:00.000Z",
when: '2001-06-24T09:00:00.000Z',
},
},
{
issueNumber: 2,
reminder: {
when: "1999-06-24T09:00:00.000Z",
when: '1999-06-24T09:00:00.000Z',
},
},
];
Expand All @@ -49,19 +49,19 @@ describe("getPastDueReminders", () => {
expect(results.length).toBe(1);
expect(results[0].issueNumber).toBe(2);
});
test("can handle malformed date", () => {
test('can handle malformed date', () => {
const today = new Date(2000, 1, 1);
const items = [
{
issueNumber: 1,
reminder: {
when: "blah",
when: 'blah',
},
},
{
issueNumber: 2,
reminder: {
when: "1999-06-24T09:00:00.000Z",
when: '1999-06-24T09:00:00.000Z',
},
},
];
Expand All @@ -73,21 +73,21 @@ describe("getPastDueReminders", () => {
});
});

describe("createComments", () => {
test("creates comments parameters array", () => {
describe('createComments', () => {
test('creates comments parameters array', () => {
const items = [
{
issueNumber: 1,
reminder: {
who: "steve",
what: "to something",
who: 'steve',
what: 'to something',
},
},
{
issueNumber: 2,
reminder: {
who: "scott",
what: "to something else",
who: 'scott',
what: 'to something else',
},
},
];
Expand All @@ -96,14 +96,14 @@ describe("createComments", () => {

expect(result[0]).toEqual({
issue_number: 1,
body: ":wave: @steve, to something",
body: ':wave: @steve, to something',
});
expect(result.length).toBe(2);
});
});

describe("markAsNotified", () => {
test("removes reminder from body but leaves active ones", () => {
describe('markAsNotified', () => {
test('removes reminder from body but leaves active ones', () => {
const body = `testing
<!-- bot: {"reminders":[{"id":1,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"},{"id":2,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"}]} -->`;
Expand All @@ -117,12 +117,12 @@ describe("markAsNotified", () => {

expect(markAsNotified(body, 1)).toEqual(expected);
});
test("removes reminder from body", () => {
test('removes reminder from body', () => {
const body = `testing
<!-- bot: {"reminders":[{"id":1,"who":"stdavis","what":"celebrate","when":"2020-06-24T09:28:33.000Z"}]} -->`;

const expected = { body: "testing", hasActive: false };
const expected = { body: 'testing', hasActive: false };

expect(markAsNotified(body, 1)).toEqual(expected);
});
Expand Down
Loading

0 comments on commit 4b59f45

Please sign in to comment.