Skip to content

Commit

Permalink
Hotfix reduce call. Use complete inputs object as argument for fix …
Browse files Browse the repository at this point in the history
…functions in `inputFixes`.
  • Loading branch information
emibcn committed Jun 19, 2021
1 parent 1392bb5 commit a5f0078
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
34 changes: 29 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ createBadgeFromInputs({
inputMap: {
...defaultOptionsMap,
gradient: 'gradient',
path: 'file',
},
));
});
```

### Change input fixes
Expand Down Expand Up @@ -89,14 +88,39 @@ createBadgeFromInputs({
inputFixes: {
...defaultInputFixes,
// Color gradient as Array, split with a pipe '|' instead of a comma ','
gradient: (gradient) => gradient
gradient: ({ gradient }) => gradient
.split('|')
// Clean spaces
.map((color) => color.trim(' ')),
},
));
},
});
```

### Change `path` input
The input `path` is the only one **not** passed to `gradientBadge`. Iy you want to change it's input name (and still use it), you'll need to ensure it's named `path`:

```javascript
const {
createBadgeFromInputs,
defaultInputMap,
defaultInputFixes
} = require('github-badge-action');

createBadgeFromInputs({
inputMap: {
...defaultOptionsMap,
// Use `file` instead of `path` as the input name
path: 'file',
},
inputFixes: {
...defaultInputFixes,
// Color gradient as Array, split with a pipe '|' instead of a comma ','
path: ({ file }) => file,
},
});
```


### Available options
#### `label`

Expand Down
6 changes: 3 additions & 3 deletions src/defaultInputFixes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const defaultInputFixes = {
// Ensure string
status: (status) => `${status}`,
status: ({ status }) => `${status}`,

// Ensure null if empty
icon: (icon) => (icon?.length ? icon : null),
icon: ({ icon }) => (icon?.length ? icon : null),

// Color gradient as Array
gradient: (gradient) =>
gradient: ({ gradient }) =>
gradient
.split(',')

Expand Down
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ const createBadgeFromInputs = ({
try {
// Get action inputs
const inputs = Object.entries(inputMap).reduce(
(acc, [key, input]) => ({
(acc, [key, inputName]) => ({
...acc,
key: core.getInput(input),
[key]: core.getInput(inputName),
}),
{}
);

// Fix some inputs
for (const [key, fn] of Object.entries(inputFixes)) {
inputs[key] = fn(inputs[key]);
inputs[key] = fn(inputs);
}

console.log('Generate badge using the given inputs and defaults: ', inputs);
Expand Down

0 comments on commit a5f0078

Please sign in to comment.