Skip to content

Commit

Permalink
improve edit summary usage
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Mar 26, 2023
1 parent ac8781d commit a51db77
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 14 deletions.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ jobs:
# Run build and ensure tests are passing before deployment
- run: npm run --if-present build
- run: npm run --if-present test
- uses: wikimedia-gadgets/deploy-action@v1
- name: Deploy to Wikipedia
uses: wikimedia-gadgets/deploy-action@v1
with:
paths: 'src/myscript.js User:SD0001/myscript.js'
apiUrl: 'https://en.wikipedia.org/w/api.php'
Expand All @@ -34,6 +35,12 @@ jobs:
### OR ###
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}

# Optional, defaults to "Updating from repo at $BRANCH ($SHA)"
# If provided, $BRANCH will be expanded to branch name, $SHA to 8-character SHA1,
# and $SOURCE to the source file path.
# You can also use values from the context (https://docs.github.com/en/actions/learn-github-actions/contexts#github-context) such as ${{github.repository}}
editSummary: ''
```
This action as written above will be triggered every time a commit is pushed to master branch. For alternative trigger mechanisms (such as triggering when a release is published), refer to [GitHub docs](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on).
Expand Down
4 changes: 3 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ description: 'Deploy user scripts or gadgets to Wikimedia sites'
author: 'Siddharth VP'
inputs:
apiUrl:
required: true
description: 'API URL of the wiki, eg. https://en.wikipedia.org/w/api.php'
required: true
username:
description: 'Username for use with BotPassword authentication'
password:
Expand All @@ -13,8 +13,10 @@ inputs:
description: 'Access token for use with OAuth2 authentication'
paths:
description: 'Paths to sync with wiki pages. Can be multiple lines. Each line should be path-to-file-in-repo <space> wiki-page-title. Note the local file path must not contain spaces.'
required: true
editSummary:
description: 'Edit summary to use while updating pages'
default: 'Updating from repo at $BRANCH ($SHA)'
runs:
using: 'node16'
main: 'dist/index.js'
Expand Down
13 changes: 8 additions & 5 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ export async function run(): Promise<void> {
)
}

const context = github.context
const paths = await processPaths(core.getMultilineInput('paths'))
const editSummary =
core.getInput('editSummary') || `Updating from repo at ${context.ref}`
const paths = await processPaths(
core.getMultilineInput('paths', {required: true})
)

const editSummaryRaw =
core.getInput('editSummary') || 'Updating from repo at $BRANCH ($SHA)'
const baseRequestParams = {apiUrl, username, password, oauth2Token}

await requestEdits(baseRequestParams, paths, editSummary)
await requestEdits(baseRequestParams, paths, editSummaryRaw)
} catch (error) {
if (error instanceof Error) core.setFailed(error.message)
}
Expand Down Expand Up @@ -68,11 +69,15 @@ export async function processPath(
export function requestEdits(
baseParams: Record<string, string>,
paths: Array<[string, string]>,
editSummary: string
editSummaryRaw: string
) {
return Promise.all(
paths.map(async path => {
let [sourceFile, wikiPage] = path
const editSummary = editSummaryRaw
.replace(/\$BRANCH/, github.context.ref.replace(/^refs\/heads\//, ''))
.replace(/\$SHA/, github.context.sha.slice(0, 8))
.replace(/\$SOURCE/, sourceFile)
let requestParams = {
...baseParams,
page: wikiPage,
Expand Down

0 comments on commit a51db77

Please sign in to comment.