Skip to content

Commit

Permalink
feat: added override for protected branch detection
Browse files Browse the repository at this point in the history
fix: filtered nullable sponser list
  • Loading branch information
akhilmhdh committed Mar 4, 2022
1 parent 65e1e0d commit a0a18d5
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 44 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
name: A job to automate contrib in readme
steps:
- name: Contribute List
uses: akhilmhdh/contributors-readme-action@v2.3.3
uses: akhilmhdh/contributors-readme-action@v2.3.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Expand All @@ -44,7 +44,7 @@ That's it!
To add it to your to your existing workflow, append this to your current `.yml` workflow script.

```yml
- uses: akhilmhdh/contributors-readme-action@v2.3.3
- uses: akhilmhdh/contributors-readme-action@v2.3.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
```
Expand Down Expand Up @@ -125,26 +125,28 @@ You can add these optional parameters in your action script to modify the appear

```yml
- name: Contribute List
uses: akhilmhdh/contributors-readme-action@v2.3.3
uses: akhilmhdh/contributors-readme-action@v2.3.4
with:
image_size: 100
```

| Option | Default Value | Description | Required |
| --------------------- | ---------------------------------------- | --------------------------------------------------------------- | -------- |
| image_size | 100(px) | Size of square images in the stack | false |
| readme_path | README.md | Path of the readme file you want to update | false |
| use_username | false | To use username instead of full name | false |
| columns_per_row | 6 | Number of columns in a row | false |
| collaborators | direct | Type of collaborators options: all/direct/outside | false |
| commit_message | contrib-readme-action has updated readme | Commit message of the github action | false |
| committer_username | "" | Username on commit | false |
| committer_email | "" | Email id of committer | false |
| pr_title_on_protected | contributors readme action update | Title of the PR that will be created if the branch is protected | false |
| Option | Default Value | Description | Required |
| ----------------------------- | ---------------------------------------- | --------------------------------------------------------------- | -------- |
| image_size | 100(px) | Size of square images in the stack | false |
| readme_path | README.md | Path of the readme file you want to update | false |
| use_username | false | To use username instead of full name | false |
| columns_per_row | 6 | Number of columns in a row | false |
| collaborators | direct | Type of collaborators options: all/direct/outside | false |
| commit_message | contrib-readme-action has updated readme | Commit message of the github action | false |
| committer_username | "" | Username on commit | false |
| committer_email | "" | Email id of committer | false |
| pr_title_on_protected | contributors readme action update | Title of the PR that will be created if the branch is protected | false |
| auto_detect_branch_protection | true | To override auto protected branch detection | false |

> committer_username and committer_email both must be provided to use as a replacement to GH action committer

> The action will update Readme as PR when the branch is protected, else it will directly commit it.
> But if your branch is protected and you passed personal access token to avoid PR mode by trusting the action, you could set auto_detect_branch_protection to false

### Outputs

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ inputs:
committer_email:
description: "email id of committer"
required: false
auto_detect_branch_protection:
description: "check if branch is protected"
default: "true"
required: false
pr_title_on_protected:
description: "Title of the PR that will be created if the branch is protected"
default: "contributors readme action update"
Expand Down
70 changes: 55 additions & 15 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5149,7 +5149,7 @@ Object.defineProperty(Response.prototype, Symbol.toStringTag, {
});

const INTERNALS$2 = Symbol('Request internals');
const URL = whatwgUrl.URL;
const URL = Url.URL || whatwgUrl.URL;

// fix an issue where "format", "parse" aren't a named export for node <10
const parse_url = Url.parse;
Expand Down Expand Up @@ -5412,9 +5412,17 @@ AbortError.prototype = Object.create(Error.prototype);
AbortError.prototype.constructor = AbortError;
AbortError.prototype.name = 'AbortError';

const URL$1 = Url.URL || whatwgUrl.URL;

// fix an issue where "PassThrough", "resolve" aren't a named export for node <10
const PassThrough$1 = Stream.PassThrough;
const resolve_url = Url.resolve;

const isDomainOrSubdomain = function isDomainOrSubdomain(destination, original) {
const orig = new URL$1(original).hostname;
const dest = new URL$1(destination).hostname;

return orig === dest || orig[orig.length - dest.length - 1] === '.' && orig.endsWith(dest);
};

/**
* Fetch function
Expand Down Expand Up @@ -5502,7 +5510,19 @@ function fetch(url, opts) {
const location = headers.get('Location');

// HTTP fetch step 5.3
const locationURL = location === null ? null : resolve_url(request.url, location);
let locationURL = null;
try {
locationURL = location === null ? null : new URL$1(location, request.url).toString();
} catch (err) {
// error here can only be invalid URL in Location: header
// do not throw when options.redirect == manual
// let the user extract the errorneous redirect URL
if (request.redirect !== 'manual') {
reject(new FetchError(`uri requested responds with an invalid redirect URL: ${location}`, 'invalid-redirect'));
finalize();
return;
}
}

// HTTP fetch step 5.5
switch (request.redirect) {
Expand Down Expand Up @@ -5550,6 +5570,12 @@ function fetch(url, opts) {
size: request.size
};

if (!isDomainOrSubdomain(request.url, locationURL)) {
for (const name of ['authorization', 'www-authenticate', 'cookie', 'cookie2']) {
requestOpts.headers.delete(name);
}
}

// HTTP-redirect fetch step 9
if (res.statusCode !== 303 && request.body && getTotalBytes(request) === null) {
reject(new FetchError('Cannot follow redirect with body being a readable stream', 'unsupported-redirect'));
Expand Down Expand Up @@ -8445,13 +8471,13 @@ let fillPool = bytes => {
poolOffset += bytes
}
let random = bytes => {
fillPool(bytes)
fillPool((bytes -= 0))
return pool.subarray(poolOffset - bytes, poolOffset)
}
let customRandom = (alphabet, size, getRandom) => {
let customRandom = (alphabet, defaultSize, getRandom) => {
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
let step = Math.ceil((1.6 * mask * size) / alphabet.length)
return () => {
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
return (size = defaultSize) => {
let id = ''
while (true) {
let bytes = getRandom(step)
Expand All @@ -8463,9 +8489,10 @@ let customRandom = (alphabet, size, getRandom) => {
}
}
}
let customAlphabet = (alphabet, size) => customRandom(alphabet, size, random)
let customAlphabet = (alphabet, size = 21) =>
customRandom(alphabet, size, random)
let nanoid = (size = 21) => {
fillPool(size)
fillPool((size -= 0))
let id = ''
for (let i = poolOffset - size; i < poolOffset; i++) {
id += urlAlphabet[pool[i] & 63]
Expand Down Expand Up @@ -8781,6 +8808,11 @@ query($owner:String!) {
login
avatarUrl
}
... on Organization {
name
login
avatarUrl
}
}
}
}
Expand All @@ -8801,6 +8833,11 @@ query($owner:String!) {
login
avatarUrl
}
... on Organization {
name
login
avatarUrl
}
}
}
}
Expand Down Expand Up @@ -8831,6 +8868,7 @@ async function run() {
const name = (0,core.getInput)('committer_username').trim();
const email = (0,core.getInput)('committer_email').trim();
const prTitle = (0,core.getInput)('pr_title_on_protected').trim();
const auto_detect_branch_protection = (0,core.getBooleanInput)('auto_detect_branch_protection');

const ref = github.context.ref;
const branch = github.context.ref.split('/').pop();
Expand All @@ -8845,7 +8883,7 @@ async function run() {
const nwo = process.env['GITHUB_REPOSITORY'] || '/';
const [owner, repo] = nwo.split('/');
const branchDetails = await src_octokit.rest.repos.getBranch({ owner, repo, branch });
const isProtected = branchDetails.data.protected;
const isProtected = branchDetails.data.protected && auto_detect_branch_protection;

const userInfo = await src_octokit.rest.users.getByUsername({ username: owner });
const isOrg = userInfo.data.type === 'Organization';
Expand Down Expand Up @@ -8907,11 +8945,13 @@ async function run() {

const sponsors = sponsorsList[
isOrg ? 'organization' : 'user'
].sponsorshipsAsMaintainer.nodes.map(({ sponsorEntity: { name, login, avatarUrl } }) => ({
name,
login,
avatar_url: avatarUrl
}));
].sponsorshipsAsMaintainer.nodes
.filter(el => Boolean(el))
.map(({ sponsorEntity: { name, login, avatarUrl } }) => ({
name,
login,
avatar_url: avatarUrl
}));

const bots = [...contributorsBots, ...collaboratorsBots];
// parse the base64 readme
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"@actions/core": "^1.6.0",
"@actions/github": "^5.0.0",
"nanoid": "^3.1.30"
"nanoid": "^3.3.1"
},
"devDependencies": {
"@babel/preset-env": "^7.15.6",
Expand Down
17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { nanoid } from 'nanoid';
import { getInput, setOutput, setFailed } from '@actions/core';
import { getInput, setOutput, setFailed, getBooleanInput } from '@actions/core';
import { context } from '@actions/github';
import octokit from './octokit';

Expand All @@ -20,6 +20,7 @@ async function run() {
const name = getInput('committer_username').trim();
const email = getInput('committer_email').trim();
const prTitle = getInput('pr_title_on_protected').trim();
const auto_detect_branch_protection = getBooleanInput('auto_detect_branch_protection');

const ref = context.ref;
const branch = context.ref.split('/').pop();
Expand All @@ -34,7 +35,7 @@ async function run() {
const nwo = process.env['GITHUB_REPOSITORY'] || '/';
const [owner, repo] = nwo.split('/');
const branchDetails = await octokit.rest.repos.getBranch({ owner, repo, branch });
const isProtected = branchDetails.data.protected;
const isProtected = branchDetails.data.protected && auto_detect_branch_protection;

const userInfo = await octokit.rest.users.getByUsername({ username: owner });
const isOrg = userInfo.data.type === 'Organization';
Expand Down Expand Up @@ -96,11 +97,13 @@ async function run() {

const sponsors = sponsorsList[
isOrg ? 'organization' : 'user'
].sponsorshipsAsMaintainer.nodes.map(({ sponsorEntity: { name, login, avatarUrl } }) => ({
name,
login,
avatar_url: avatarUrl
}));
].sponsorshipsAsMaintainer.nodes
.filter(el => Boolean(el))
.map(({ sponsorEntity: { name, login, avatarUrl } }) => ({
name,
login,
avatar_url: avatarUrl
}));

const bots = [...contributorsBots, ...collaboratorsBots];
// parse the base64 readme
Expand Down
5 changes: 5 additions & 0 deletions src/query/getOrgSponsorsList.gql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ query($owner:String!) {
login
avatarUrl
}
... on Organization {
name
login
avatarUrl
}
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/query/getSponsorsList.gql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ query($owner:String!) {
login
avatarUrl
}
... on Organization {
name
login
avatarUrl
}
}
}
}
Expand Down

0 comments on commit a0a18d5

Please sign in to comment.