Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@jamesives/github-sponsors-readme-action

Package Overview
Dependencies
5
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.3 to 1.0.4

.github/assets/placeholder.png

28

__tests__/lib.test.ts
import {setFailed} from '@actions/core'
import nock from 'nock'
import {promises} from 'fs'
import {GitHubResponse, PrivacyLevel, Urls} from '../src/constants'

@@ -65,3 +66,3 @@ import run from '../src/lib'

it('should run through the commands', async () => {
it('should run through the commands and enter a success state', async () => {
const action = {

@@ -74,2 +75,24 @@ token: '123',

maximum: 0,
marker: 'sponsor',
organization: false,
fallback: ''
}
// Valid file structure
await promises.writeFile(
'README.test.md',
'Generated README file for testing <!-- sponsor --><!-- sponsor --> - do not commit'
)
await run(action)
})
it('should run through the commands and enter a skipped state', async () => {
const action = {
token: '123',
file: 'SPONSORS.test.md',
template:
'<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="60px" alt="" /></a>',
minimum: 0,
maximum: 0,
marker: 'sponsors',

@@ -80,2 +103,5 @@ organization: false,

// Purposely write incorrect data
await promises.writeFile('SPONSORS.test.md', 'nothing here')
await run(action)

@@ -82,0 +108,0 @@ })

@@ -1,2 +0,2 @@

import {GitHubResponse, PrivacyLevel, Urls} from '../src/constants'
import {GitHubResponse, PrivacyLevel, Status, Urls} from '../src/constants'
import {generateFile, generateTemplate, getSponsors} from '../src/template'

@@ -416,5 +416,66 @@ import {promises} from 'fs'

expect(await generateFile(response, action)).toBe(undefined)
expect(await generateFile(response, action)).toBe(Status.SUCCESS)
})
it('should go into a skipped state if there is no marker found in the template', async () => {
const response: GitHubResponse = {
data: {
viewer: {
sponsorshipsAsMaintainer: {
totalCount: 2,
pageInfo: {
endCursor: 'MQ'
},
nodes: [
{
createdAt: '123',
privacyLevel: PrivacyLevel.PUBLIC,
tier: {
monthlyPriceInCents: 12000
},
sponsorEntity: {
name: 'James Ives',
login: 'JamesIves',
url: 'https://github.com/JamesIves'
}
},
{
createdAt: '123',
privacyLevel: PrivacyLevel.PUBLIC,
tier: {
monthlyPriceInCents: 12000
},
sponsorEntity: {
name: 'Montezuma Ives',
login: 'MontezumaIves',
url: 'https://github.com/MontezumaIves'
}
}
]
}
}
}
}
const action = {
token: '123',
file: 'README.test.md',
template:
'<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="60px" alt="" /></a>',
minimum: 6000,
maximum: 10000,
marker: 'sponsors',
organization: false,
fallback: 'There are no sponsors in this tier'
}
// Purposely write incorrect data
await promises.writeFile(
'README.test.md',
'Generated README file for testing <!-- sponsorrrr --><!-- sponsors --> - do not commit'
)
expect(await generateFile(response, action)).toBe(Status.SKIPPED)
})
it('should catch when a function throws an error', async () => {

@@ -421,0 +482,0 @@ ;(info as jest.Mock).mockImplementationOnce(() => {

3

lib/constants.d.ts

@@ -66,3 +66,4 @@ export interface ActionInterface {

FAILED = "failed",
RUNNING = "running"
RUNNING = "running",
SKIPPED = "skipped"
}

@@ -69,0 +70,0 @@ export declare enum Urls {

@@ -40,2 +40,3 @@ "use strict";

Status["RUNNING"] = "running";
Status["SKIPPED"] = "skipped";
})(Status = exports.Status || (exports.Status = {}));

@@ -42,0 +43,0 @@ var Urls;

@@ -40,3 +40,3 @@ "use strict";

const response = yield template_1.getSponsors(settings);
yield template_1.generateFile(response, settings);
status = yield template_1.generateFile(response, settings);
}

@@ -50,3 +50,5 @@ catch (error) {

? 'There was an error generating sponsors. ❌'
: 'The data was succesfully retrieved and saved! ✅ 💖'}`);
: status === constants_1.Status.SUCCESS
? 'The data was succesfully retrieved and saved! ✅ 💖'
: `Unable to locate markers in your file. Please check the documentation and try again. ⚠️`}`);
core_1.setOutput('sponsorship-status', status);

@@ -53,0 +55,0 @@ }

import 'cross-fetch/polyfill';
import { ActionInterface, GitHubResponse } from './constants';
import { ActionInterface, GitHubResponse, Status } from './constants';
/** Fetches */
export declare function getSponsors(action: ActionInterface): Promise<GitHubResponse>;
export declare function generateTemplate(response: GitHubResponse, action: ActionInterface): string;
export declare function generateFile(response: GitHubResponse, action: ActionInterface): Promise<void>;
export declare function generateFile(response: GitHubResponse, action: ActionInterface): Promise<Status>;

@@ -107,4 +107,8 @@ "use strict";

let data = yield fs_1.promises.readFile(action.file, 'utf8');
if (!regex.test(data)) {
return constants_1.Status.SKIPPED;
}
data = data.replace(regex, `$1${generateTemplate(response, action)}$2`);
yield fs_1.promises.writeFile(action.file, data);
return constants_1.Status.SUCCESS;
}

@@ -111,0 +115,0 @@ catch (error) {

@@ -5,3 +5,3 @@ {

"author": "James Ives <iam@jamesiv.es> (https://jamesiv.es)",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",

@@ -36,5 +36,5 @@ "main": "lib/lib.js",

"@actions/core": "1.2.6",
"@actions/io": "1.0.2",
"@actions/io": "1.1.0",
"cross-fetch": "3.1.4",
"mustache": "4.0.0"
"mustache": "4.2.0"
},

@@ -44,5 +44,5 @@ "devDependencies": {

"@types/jest": "26.0.23",
"@types/mustache": "4.0.1",
"@types/node": "14.0.1",
"@typescript-eslint/eslint-plugin": "4.22.0",
"@types/mustache": "4.1.1",
"@types/node": "15.0.1",
"@typescript-eslint/eslint-plugin": "4.22.1",
"@typescript-eslint/parser": "4.22.0",

@@ -53,9 +53,9 @@ "eslint": "7.25.0",

"eslint-plugin-prettier": "3.4.0",
"jest": "25.1.0",
"jest-circus": "26.0.1",
"nock": "13.0.0",
"prettier": "2.0.2",
"jest": "25.5.4",
"jest-circus": "26.6.3",
"nock": "13.0.11",
"prettier": "2.2.1",
"ts-jest": "25.5.1",
"typescript": "3.9.2"
"typescript": "3.9.9"
}
}
<p align="center">
<a href="https://github.com/marketplace/actions/fetch-api-data">
<img width="200px" src="./.github/assets/icon.png">
<a href="https://github.com/JamesIves/github-sponsors-readme-action">
<img width="200px" src="https://github.com/JamesIves/github-sponsors-readme-action/raw/dev/.github/assets/icon.png">
</a>

@@ -33,2 +33,8 @@ </p>

<p align="center"><a href="https://github.com/sponsors/JamesIves">Made possible by the following</a>:</p>
<p align="center">
<!-- real-sponsors --><a href="https://github.com/Chooksta69"><img src="https://github.com/Chooksta69.png" width="40px" alt="" /></a><!-- real-sponsors -->
</p>
## Getting Started ✈️

@@ -78,6 +84,5 @@

#### Install as a Node Module 📦
If you'd like to use the functionality provided by this action in your own action you can install it using [yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/get-npm) by running the following commands. It's available on both the [npm](https://www.npmjs.com/package/@jamesives/github-sponsors-readme-action) and [GitHub registry](https://github.com/JamesIves/github-sponsors-readme-action/packages/229982).
If you'd like to use the functionality provided by this action in your own action you can install it using [yarn](https://yarnpkg.com/) or [npm](https://www.npmjs.com/get-npm) by running the following commands. It's available on both the [npm](https://www.npmjs.com/package/@jamesives/github-sponsors-readme-action) and [GitHub registry](https://github.com/JamesIves/github-sponsors-readme-action/packages/229982).

@@ -95,3 +100,3 @@ ```

```javascript
import run from "@jamesives/github-sponsors-readme-action";
import run from '@jamesives/github-sponsors-readme-action'

@@ -118,10 +123,10 @@ run(configuration)

| Key | Value Information | Type | Required |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `organization` | If you're displaying sponsorship information as an organization you should toggle this option to `true`. You also need to provide the action with an `org:read` scoped PAT. | `with` | **No** |
| `minimum` | Using this input you can set the minimum sponsorship threshold. For example setting this to `500` will only display sponsors who give of `$5 USD` and more. By default the action will display all of your sponsors. | `with` | **No** |
| `maximum` | Using this input you can set the minimum sponsorship threshold. For example setting this to `500` will only display sponsors who give of `$5 USD` and less. By default the action will display all of your sponsors. | `with` | **No** |
| Key | Value Information | Type | Required |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `organization` | If you're displaying sponsorship information as an organization you should toggle this option to `true`. You also need to provide the action with an `org:read` scoped PAT. | `with` | **No** |
| `minimum` | Using this input you can set the minimum sponsorship threshold. For example setting this to `500` will only display sponsors who give of `$5 USD` and more. By default the action will display all of your sponsors. | `with` | **No** |
| `maximum` | Using this input you can set the minimum sponsorship threshold. For example setting this to `500` will only display sponsors who give of `$5 USD` and less. By default the action will display all of your sponsors. | `with` | **No** |
| `marker` | This allows you to modify the marker comment that is placed in your file. By default this is set to sponsors - `<!-- sponsors --> <!-- sponsors -->`, if you set this to `gold` for example you can place `<!-- gold --> <!-- gold -->` in your file. | `with` | **No** |
| `fallback` | Allows you to specify a fallback if you have no sponsors. By default nothing is displayed. | `with` | **No** |
| `template` | Allows you to modify the default template. Please refer to the `template` section of this README for more information. | `with` | **No** |
| `fallback` | Allows you to specify a fallback if you have no sponsors. By default nothing is displayed. | `with` | **No** |
| `template` | Allows you to modify the default template. Please refer to the `template` section of this README for more information. | `with` | **No** |

@@ -136,2 +141,4 @@ #### Deployment Status

| `failed` | The `failed` status indicates that the action encountered an error while trying to generate the README. |
| `skipped` | The `skipped` status indicates that the action could not locate the markers in your .md file. |
| `running` | The `running` status indicates that the action is actively working. |

@@ -138,0 +145,0 @@ ---

@@ -89,3 +89,4 @@ import {getInput} from '@actions/core'

FAILED = 'failed',
RUNNING = 'running'
RUNNING = 'running',
SKIPPED = 'skipped'
}

@@ -92,0 +93,0 @@

@@ -34,3 +34,3 @@ import {info, setFailed, setOutput} from '@actions/core'

const response = await getSponsors(settings)
await generateFile(response, settings)
status = await generateFile(response, settings)
} catch (error) {

@@ -44,3 +44,5 @@ status = Status.FAILED

? 'There was an error generating sponsors. ❌'
: 'The data was succesfully retrieved and saved! ✅ 💖'
: status === Status.SUCCESS
? 'The data was succesfully retrieved and saved! ✅ 💖'
: `Unable to locate markers in your file. Please check the documentation and try again. ⚠️`
}`

@@ -47,0 +49,0 @@ )

@@ -9,2 +9,3 @@ import 'cross-fetch/polyfill'

SponsorshipsAsMaintainer,
Status,
Urls

@@ -130,3 +131,3 @@ } from './constants'

action: ActionInterface
): Promise<void> {
): Promise<Status> {
try {

@@ -142,5 +143,11 @@ info(`Generating updated ${action.file} file… 📁`)

if (!regex.test(data)) {
return Status.SKIPPED
}
data = data.replace(regex, `$1${generateTemplate(response, action)}$2`)
await promises.writeFile(action.file, data)
return Status.SUCCESS
} catch (error) {

@@ -147,0 +154,0 @@ throw new Error(

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc