Skip to content

Commit

Permalink
Merge branch 'dev' into releases/v1
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Nov 28, 2023
2 parents a2d75a8 + b2e036a commit 749e6dc
Show file tree
Hide file tree
Showing 13 changed files with 509 additions and 402 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
Expand All @@ -40,9 +40,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@releases/v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: dev

# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
Expand All @@ -40,7 +40,7 @@ jobs:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# Setup .npmrc file to publish to GitHub Packages
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: 16
registry-url: 'https://npm.pkg.github.com'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/sponsors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@v1
with:
token: ${{ secrets.PAT }}
file: 'README.md'
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="50px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
maximum: 9999
maximum: 4999
marker: 'real-sponsors'

- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@v1
with:
token: ${{ secrets.PAT }}
file: 'README.md'
minimum: 10000
minimum: 5000
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="80px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
marker: 'real-premium'

Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v14.18.1
v20.10.0
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</p>

<p align="center">
<!-- real-sponsors --><a href="https://github.com/Chooksta69"><img src="https://github.com/Chooksta69.png" width="50px" alt="Chooksta69" /></a>&nbsp;&nbsp;<a href="https://github.com/robjtede"><img src="https://github.com/robjtede.png" width="50px" alt="robjtede" /></a>&nbsp;&nbsp;<a href="https://github.com/hadley"><img src="https://github.com/hadley.png" width="50px" alt="hadley" /></a>&nbsp;&nbsp;<a href="https://github.com/kevinchalet"><img src="https://github.com/kevinchalet.png" width="50px" alt="kevinchalet" /></a>&nbsp;&nbsp;<!-- real-sponsors -->
<!-- real-sponsors --><a href="https://github.com/Chooksta69"><img src="https://github.com/Chooksta69.png" width="50px" alt="Chooksta69" /></a>&nbsp;&nbsp;<a href="https://github.com/robjtede"><img src="https://github.com/robjtede.png" width="50px" alt="robjtede" /></a>&nbsp;&nbsp;<a href="https://github.com/hadley"><img src="https://github.com/hadley.png" width="50px" alt="hadley" /></a>&nbsp;&nbsp;<a href="https://github.com/kevinchalet"><img src="https://github.com/kevinchalet.png" width="50px" alt="kevinchalet" /></a>&nbsp;&nbsp;<a href="https://github.com/sckott"><img src="https://github.com/sckott.png" width="50px" alt="sckott" /></a>&nbsp;&nbsp;<a href="https://github.com/electrovir"><img src="https://github.com/electrovir.png" width="50px" alt="electrovir" /></a>&nbsp;&nbsp;<!-- real-sponsors -->
</p>

## Getting Started ✈️
Expand Down Expand Up @@ -125,14 +125,14 @@ The following options must be configured.

#### Optional Choices

| Key | Value Information | Type | Required |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `organization` | If you're displaying sponsorship information as or for an organization you should toggle this option to `true`. You also need to provide the action with an `read:org` and `read:user` 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 maximum 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** |
| Key | Value Information | Type | Required |
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ | -------- |
| `organization` | If you're displaying sponsorship information as or for an organization you should toggle this option to `true`. You also need to provide the action with an `read:org` and `read:user` scoped PAT. **Note**: The PAT must belong to an owner of the organization. | `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 maximum 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** |

#### Deployment Status

Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@jamesives/github-sponsors-readme-action",
"description": "This GitHub Action will automatically add your GitHub Sponsors to your README. It can be configured in multiple ways allowing you to display and breakdown your sponsors by price tier with fallbacks.",
"author": "James Ives <iam@jamesiv.es> (https://jamesiv.es)",
"version": "1.2.1",
"version": "1.2.2",
"license": "MIT",
"main": "lib/lib.js",
"types": "lib/lib.d.ts",
Expand Down Expand Up @@ -33,26 +33,26 @@
"github-action"
],
"dependencies": {
"@actions/core": "1.9.1",
"@actions/io": "1.1.2",
"cross-fetch": "3.1.5",
"@actions/core": "1.10.1",
"@actions/io": "1.1.3",
"cross-fetch": "3.1.6",
"mustache": "4.2.0"
},
"devDependencies": {
"@types/async-retry": "1.4.3",
"@types/jest": "27.4.1",
"@types/mustache": "4.2.1",
"@types/node": "18.7.18",
"@typescript-eslint/eslint-plugin": "5.39.0",
"@typescript-eslint/parser": "5.36.2",
"eslint": "8.24.0",
"@types/mustache": "4.2.5",
"@types/node": "20.10.0",
"@typescript-eslint/eslint-plugin": "5.62.0",
"@typescript-eslint/parser": "5.62.0",
"eslint": "8.54.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-jest": "27.0.4",
"eslint-plugin-jest": "27.4.2",
"eslint-plugin-prettier": "4.2.1",
"jest": "27.5.1",
"jest-circus": "27.5.1",
"nock": "13.2.9",
"prettier": "2.7.1",
"nock": "13.3.1",
"prettier": "2.8.4",
"ts-jest": "27.1.4",
"typescript": "4.8.4"
}
Expand Down
33 changes: 28 additions & 5 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {getInput} from '@actions/core'
import {isNullOrUndefined} from './util'

/**
* Describes the action interface.
*/
export interface ActionInterface {
/** Deployment token. */
token?: string
Expand All @@ -20,7 +23,9 @@ export interface ActionInterface {
organization: boolean
}

// Required action data that gets initialized when running within the GitHub Actions environment.
/**
* Gets the action configuration.
*/
export const action = {
token: getInput('token'),
template: !isNullOrUndefined(getInput('template'))
Expand All @@ -44,7 +49,9 @@ export const action = {
: false
}

/** Describes the response from the GitHub GraphQL query. */
/**
* Describes the sponsor object.
*/
export interface Sponsor {
sponsorEntity: {
name: string | null
Expand All @@ -55,10 +62,13 @@ export interface Sponsor {
createdAt: string
privacyLevel: PrivacyLevel
tier: {
monthlyPriceInCents: number
monthlyPriceInCents?: number
}
}

/**
* Describes the response from the GitHub GraphQL query.
*/
export interface SponsorshipsAsMaintainer {
totalCount: number
pageInfo: {
Expand All @@ -67,6 +77,9 @@ export interface SponsorshipsAsMaintainer {
nodes: Sponsor[]
}

/**
* Describes the response from the GitHub GraphQL query.
*/
export interface GitHubResponse {
data: {
organization?: {
Expand All @@ -78,22 +91,32 @@ export interface GitHubResponse {
}
}

/** Types for the required action parameters. */
/**
* Describes the action interface.
*/
export type RequiredActionParameters = Pick<ActionInterface, 'token'>

/**
* Privacy levels for the sponsorship.
*/
export enum PrivacyLevel {
PUBLIC = 'PUBLIC',
PRIVATE = 'PRIVATE'
}

/** Status codes for the action. */
/**
* Statuses for the action.
*/
export enum Status {
SUCCESS = 'success',
FAILED = 'failed',
RUNNING = 'running',
SKIPPED = 'skipped'
}

/**
* URLs used within the action.
*/
export enum Urls {
GITHUB_API = 'https://api.github.com'
}
39 changes: 36 additions & 3 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {info, setFailed, setOutput} from '@actions/core'
import {
info,
setFailed,
exportVariable,
setOutput as setEnvironmentOutput
} from '@actions/core'
import {ActionInterface, Status} from './constants'
import {generateFile, getSponsors} from './template'
import {checkParameters, extractErrorMessage} from './util'
Expand All @@ -18,8 +23,35 @@ export default async function run(

try {
info(`
GitHub Sponsors Readme Action 💖
██████╗ ██╗████████╗██╗ ██╗██╗ ██╗██████╗
██╔════╝ ██║╚══██╔══╝██║ ██║██║ ██║██╔══██╗
██║ ███╗██║ ██║ ███████║██║ ██║██████╔╝
██║ ██║██║ ██║ ██╔══██║██║ ██║██╔══██╗
╚██████╔╝██║ ██║ ██║ ██║╚██████╔╝██████╔╝
╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝
███████╗██████╗ ██████╗ ███╗ ██╗███████╗ ██████╗ ██████╗ ███████╗
██╔════╝██╔══██╗██╔═══██╗████╗ ██║██╔════╝██╔═══██╗██╔══██╗██╔════╝
███████╗██████╔╝██║ ██║██╔██╗ ██║███████╗██║ ██║██████╔╝███████╗
╚════██║██╔═══╝ ██║ ██║██║╚██╗██║╚════██║██║ ██║██╔══██╗╚════██║
███████║██║ ╚██████╔╝██║ ╚████║███████║╚██████╔╝██║ ██║███████║
╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
██████╗ ███████╗ █████╗ ██████╗ ███╗ ███╗███████╗
██╔══██╗██╔════╝██╔══██╗██╔══██╗████╗ ████║██╔════╝
██████╔╝█████╗ ███████║██║ ██║██╔████╔██║█████╗
██╔══██╗██╔══╝ ██╔══██║██║ ██║██║╚██╔╝██║██╔══╝
██║ ██║███████╗██║ ██║██████╔╝██║ ╚═╝ ██║███████╗
╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚══════╝
█████╗ ██████╗████████╗██╗ ██████╗ ███╗ ██╗
██╔══██╗██╔════╝╚══██╔══╝██║██╔═══██╗████╗ ██║
███████║██║ ██║ ██║██║ ██║██╔██╗ ██║
██╔══██║██║ ██║ ██║██║ ██║██║╚██╗██║
██║ ██║╚██████╗ ██║ ██║╚██████╔╝██║ ╚████║
╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝
🚀 Getting Started Guide: https://github.com/JamesIves/github-sponsors-readme-action
❓ Discussions / Q&A: https://github.com/JamesIves/github-sponsors-readme-action/discussions
🔧 Report a Bug: https://github.com/JamesIves/github-sponsors-readme-action/issues
Expand All @@ -46,7 +78,8 @@ export default async function run(
}`
)

setOutput('sponsorship-status', status)
exportVariable('sponsorshipStatus', status)
setEnvironmentOutput('sponsorshipStatus', status)
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ export function generateTemplate(
let filteredSponsors = sponsorshipsAsMaintainer.nodes.filter(
(user: Sponsor) =>
user.privacyLevel !== PrivacyLevel.PRIVATE &&
user.tier.monthlyPriceInCents >= action.minimum
(user.tier.monthlyPriceInCents ? user.tier.monthlyPriceInCents : 0) >=
action.minimum
)

if (action.maximum > 0) {
filteredSponsors = filteredSponsors.filter(
(user: Sponsor) => user.tier.monthlyPriceInCents <= action.maximum
(user: Sponsor) =>
(user.tier.monthlyPriceInCents ? user.tier.monthlyPriceInCents : 0) <=
action.maximum
)
}

Expand All @@ -133,6 +136,9 @@ export function generateTemplate(
return template
}

/**
* Generates the updated file with the attached sponsorship template.
*/
export async function generateFile(
response: GitHubResponse,
action: ActionInterface
Expand Down
Loading

0 comments on commit 749e6dc

Please sign in to comment.