Skip to content

Commit

Permalink
Deploy Production Code for Commit 268b2bc 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Aug 17, 2022
1 parent 268b2bc commit 75224d7
Show file tree
Hide file tree
Showing 107 changed files with 4,398 additions and 809 deletions.
6 changes: 5 additions & 1 deletion lib/constants.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface Sponsor {
name: string | null;
login: string;
url: string;
websiteUrl: string | null;
};
createdAt: string;
privacyLevel: PrivacyLevel;
Expand All @@ -48,7 +49,10 @@ export interface SponsorshipsAsMaintainer {
}
export interface GitHubResponse {
data: {
viewer: {
organization?: {
sponsorshipsAsMaintainer: SponsorshipsAsMaintainer;
};
viewer?: {
sponsorshipsAsMaintainer: SponsorshipsAsMaintainer;
};
};
Expand Down
2 changes: 1 addition & 1 deletion lib/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function run(configuration) {
(0, core_1.info)(`${status === constants_1.Status.FAILED
? 'There was an error generating sponsors. ❌'
: status === constants_1.Status.SUCCESS
? 'The data was succesfully retrieved and saved! ✅ 💖'
? 'The data was successfully retrieved and saved! ✅ 💖'
: `Unable to locate markers in your file. Please check the documentation and try again. ⚠️`}`);
(0, core_1.setOutput)('sponsorship-status', status);
}
Expand Down
7 changes: 6 additions & 1 deletion lib/template.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import 'cross-fetch/polyfill';
import { ActionInterface, GitHubResponse, Status } from './constants';
/** Fetches */
/**
* Fetches sponsors from the GitHub Sponsors API.
*/
export declare function getSponsors(action: ActionInterface): Promise<GitHubResponse>;
/**
* Generates the sponsorship template.
*/
export declare function generateTemplate(response: GitHubResponse, action: ActionInterface): string;
export declare function generateFile(response: GitHubResponse, action: ActionInterface): Promise<Status>;
53 changes: 33 additions & 20 deletions lib/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ const constants_1 = require("./constants");
const mustache_1 = require("mustache");
const util_1 = require("./util");
const core_1 = require("@actions/core");
/** Fetches */
/**
* Fetches sponsors from the GitHub Sponsors API.
*/
function getSponsors(action) {
return __awaiter(this, void 0, void 0, function* () {
try {
(0, core_1.info)(`Fetching data from the GitHub API as ${action.organization ? 'Organization' : 'User'}… ⚽`);
const query = `query {
viewer {
${action.organization
? `organization (login: "${process.env.GITHUB_REPOSITORY_OWNER}")`
: `viewer`} {
login
sponsorshipsAsMaintainer(first: 100, orderBy: {field: CREATED_AT, direction: ASC}, includePrivate: true) {
totalCount
Expand All @@ -31,19 +35,17 @@ function getSponsors(action) {
}
nodes {
sponsorEntity {
${action.organization
? `
... on Organization {
name
login
url
}`
: ``}
websiteUrl
}
... on User {
name
login
url
websiteUrl
}
}
createdAt
Expand Down Expand Up @@ -74,24 +76,35 @@ function getSponsors(action) {
});
}
exports.getSponsors = getSponsors;
/**
* Generates the sponsorship template.
*/
function generateTemplate(response, action) {
let template = ``;
(0, core_1.info)('Generating template… ✨');
const { sponsorshipsAsMaintainer } = response.data.viewer;
/* Appends the template, the API call returns all users regardless of if they are hidden or not.
In an effort to respect a users decisison to be anoymous we filter these users out. */
let filteredSponsors = sponsorshipsAsMaintainer.nodes.filter((user) => user.privacyLevel !== constants_1.PrivacyLevel.PRIVATE &&
user.tier.monthlyPriceInCents >= action.minimum);
if (action.maximum > 0) {
filteredSponsors = filteredSponsors.filter((user) => user.tier.monthlyPriceInCents <= action.maximum);
const data = action.organization
? response.data.organization
: response.data.viewer;
const sponsorshipsAsMaintainer = data === null || data === void 0 ? void 0 : data.sponsorshipsAsMaintainer;
if (sponsorshipsAsMaintainer) {
/* Appends the template, the API call returns all users regardless of if they are hidden or not.
In an effort to respect a users decision to be anonymous we filter these users out. */
let filteredSponsors = sponsorshipsAsMaintainer.nodes.filter((user) => user.privacyLevel !== constants_1.PrivacyLevel.PRIVATE &&
user.tier.monthlyPriceInCents >= action.minimum);
if (action.maximum > 0) {
filteredSponsors = filteredSponsors.filter((user) => user.tier.monthlyPriceInCents <= action.maximum);
}
/** If there are no valid sponsors then we return the provided fallback. */
if (!filteredSponsors.length) {
return action.fallback;
}
filteredSponsors.map(({ sponsorEntity }) => {
template = template += (0, mustache_1.render)(action.template, sponsorEntity);
});
}
/** If there are no valid sponsors then we return the provided fallback. */
if (!filteredSponsors.length) {
return action.fallback;
else {
(0, core_1.info)(`No sponsorship data was found… ❌`);
}
filteredSponsors.map(({ sponsorEntity }) => {
template = template += (0, mustache_1.render)(action.template, sponsorEntity);
});
return template;
}
exports.generateTemplate = generateTemplate;
Expand Down
12 changes: 12 additions & 0 deletions lib/util.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import { ActionInterface } from './constants';
/**
* Utility function that checks to see if a value is undefined or not.
*/
export declare const isNullOrUndefined: (value: string | undefined | null) => boolean;
/**
* Verifies the action has the required parameters to run, otherwise throw an error.
*/
export declare const checkParameters: (action: ActionInterface) => void;
/**
* Suppresses sensitive information from being exposed in error messages.
*/
export declare const suppressSensitiveInformation: (str: string, action: ActionInterface) => string;
/**
* Extracts error message from an error.
*/
export declare const extractErrorMessage: (error: unknown) => string;
23 changes: 18 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractErrorMessage = exports.suppressSensitiveInformation = exports.checkParameters = exports.isNullOrUndefined = void 0;
/* Utility function that checks to see if a value is undefined or not. */
/**
* Utility function that checks to see if a value is undefined or not.
*/
const isNullOrUndefined = (value) => typeof value === 'undefined' || value === null || value === '';
exports.isNullOrUndefined = isNullOrUndefined;
/* Checks for the required tokens and formatting. Throws an error if any case is matched. */
/**
* Checks for the required tokens and formatting. Throws an error if any case is matched.
*/
const hasRequiredParameters = (action, params) => {
const nonNullParams = params.filter(param => !(0, exports.isNullOrUndefined)(action[param]));
return Boolean(nonNullParams.length);
};
/* Verifies the action has the required parameters to run, otherwise throw an error. */
/**
* Verifies the action has the required parameters to run, otherwise throw an error.
*/
const checkParameters = (action) => {
if (!hasRequiredParameters(action, ['token'])) {
throw new Error('No deployment token was provided. You must provide the action with a Personal Access Token scoped to user:read or org:read.');
}
};
exports.checkParameters = checkParameters;
/* Replaces all instances of a match in a string. */
/**
* Replaces all instances of a match in a string.
*/
const replaceAll = (input, find, replace) => input.split(find).join(replace);
/* Suppresses sensitive information from being exposed in error messages. */
/**
* Suppresses sensitive information from being exposed in error messages.
*/
const suppressSensitiveInformation = (str, action) => {
let value = str;
const orderedByLength = [action.token, action.token].filter(Boolean).sort((a, b) => b.length - a.length);
Expand All @@ -28,6 +38,9 @@ const suppressSensitiveInformation = (str, action) => {
return value;
};
exports.suppressSensitiveInformation = suppressSensitiveInformation;
/**
* Extracts error message from an error.
*/
const extractErrorMessage = (error) => error instanceof Error
? error.message
: typeof error == 'string'
Expand Down
1 change: 1 addition & 0 deletions node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions node_modules/@actions/core/lib/core.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion node_modules/@actions/core/lib/core.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 75224d7

Please sign in to comment.