Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow submitting reviewed extensions via issues #1034

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 45 additions & 18 deletions .github/workflows/auto-pr.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Extension issue to Pull Request conversion
on:
issues:
types: [opened, labeled, edited]
types: [labeled, edited] # We do not listen to the opened event because the issue will be labelled "New Extension" duplicating this action run.

jobs:
generate-pr:
Expand All @@ -22,44 +22,48 @@ jobs:

- name: Extract and verify extension
uses: actions/github-script@v6
id: prepare-extension
env:
BODY: ${{ github.event.issue.body }}
with:
script: |
const { extractExtension } = require('./scripts/extract-extension.js');
const { verifyExtension } = require('./scripts/check-single-extension.js')


const { error, extensionName } = await extractExtension("/tmp/ext.zip");
const reviewed = !process.env.BODY.includes("Community (Unreviewed)");
core.setOutput("reviewed", reviewed);
const { error, extensionName } = await extractExtension("/tmp/ext.zip", { reviewed });

if(error === "zip-error")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! Sadly, we were unable to properly extract your extension from its zip file. Try to create the zip with another software, and to update your original submission post with the new file. If that still doesn't work, ask a member of the extension team for help 😉`
body: `👋 Hey @${{ github.event.issue.user.login }}, thanks for your submission! Sadly, we were unable to properly extract your extension from its zip file. Try to create the zip with another software, and to update your original submission post with the new file. If that still doesn't work, ask a member of the extension team for help 😉`
})

if(error === "too-many-files")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! We are kind of confused; Your zip file contained more than one JSON file, and only one extension can be submitted at a time. Please update your original submission post with a new zip file containing only one extension file 🙏`
body: `👋 Hey @${{ github.event.issue.user.login }}, thanks for your submission! We are kind of confused; Your zip file contained more than one JSON file, and only one extension can be submitted at a time. Please update your original submission post with a new zip file containing only one extension file 🙏`
})

if(error === "no-json-found")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! We are kind of confused; Your zip file doesn't seem to contain an extension. Please update your original submission post with a new zip file containing an extension 🙏\nIf your zip does already contain an extension, make sure your file ends with ".json", and that it is at the root of your zip file (not in a sub folder!), as otherwise it will be unrecognized and ignored by the system. If you've checked and nothing seems wrong with your zip, you can ask a member of the extension team for help 😉`
body: `👋 Hey @${{ github.event.issue.user.login }}, thanks for your submission! We are kind of confused; Your zip file doesn't seem to contain an extension. Please update your original submission post with a new zip file containing an extension 🙏\nIf your zip does already contain an extension, make sure your file ends with ".json", and that it is at the root of your zip file (not in a sub folder!), as otherwise it will be unrecognized and ignored by the system. If you've checked and nothing seems wrong with your zip, you can ask a member of the extension team for help 😉`
})

if(error === "invalid-file-name")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! We are sorry, but the filename of the extension has unrecognized characters. Since filenames with weird character can cause all kinds of problems and security flaws, our system won't allow file names with other characters than normal latin upper- and lowercase characters or numbers. Additionally, the first character must be an uppercase character. Please update your original submission post with a new zip file containing your extension with another file name following those guidelines 🙏`
body: `👋 Hey @${{ github.event.issue.user.login }}, thanks for your submission! We are sorry, but the filename of the extension has unrecognized characters. Since filenames with weird character can cause all kinds of problems and security flaws, our system won't allow file names with other characters than normal latin upper- and lowercase characters or numbers. Additionally, the first character must be an uppercase character. Please update your original submission post with a new zip file containing your extension with another file name following those guidelines 🙏`
})

if(error) {
Expand All @@ -74,39 +78,55 @@ jobs:
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! We are sorry, but the filename of the extension has unrecognized characters. Since filenames with weird character can cause all kinds of problems and security flaws, our system won't allow file names with other characters than normal latin upper- and lowercase characters or numbers. Additionally, the first character must be an uppercase character. Please update your original submission post with a new zip file containing your extension with another file name following those guidelines 🙏`
body: `👋 Hey @${{ github.event.issue.user.login }}, thanks for your submission! We are sorry, but the filename of the extension has unrecognized characters. Since filenames with weird character can cause all kinds of problems and security flaws, our system won't allow file names with other characters than normal latin upper- and lowercase characters or numbers. Additionally, the first character must be an uppercase character. Please update your original submission post with a new zip file containing your extension with another file name following those guidelines 🙏`
})

if(code === "not-found")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! We are sorry, but it seems your extension file miraculously disappeared just after being extracted 🤔. This should never happen, please ask @GDevelopApp/extensions-team for assistance.`
body: `👋 Hey @${{ github.event.issue.user.login }}, thanks for your submission! We are sorry, but it seems your extension file miraculously disappeared just after being extracted 🤔. This should never happen, please ask @GDevelopApp/extensions-team for assistance.`
})

if(code === "duplicated" )
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! We are sorry, but it seems we already have a reviewed extension with that name. Extensions cannot be in both the community and reviewed extensions list at once. If you are trying to update that extension, please ask a member of the extension team for help. If the name clash is a coincidence, please update your original submission post with a new zip file containing your extension with a file name that is not already taken 🙏`
body: `👋 Hey @${{ github.event.issue.user.login }}, thanks for your submission! We are sorry, but it seems we already have a ${reviewed ? 'community' : 'reviewed'} extension with that name. Extensions cannot share a name between the community and reviewed extensions list. If you are trying to update that other extension, please make sure you selected the correct review type. If the name clash is a coincidence, please update your original submission post with a new zip file containing your extension with a file and extension name that is not already taken 🙏`
})

if(code === "invalid-json")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! We are sorry, but your extension file inside the zip file seems to be damaged, as our system wasn't able to understand its content. Try to re-export the extension JSON file, or to create the zip with another software, and to update your original submission post with the new zip file. If that still doesn't work, ask a member of the extension team for help 😉`
body: `👋 Hey @${{ github.event.issue.user.login }}, thanks for your submission! We are sorry, but your extension file inside the zip file seems to be damaged, as our system wasn't able to understand its content. Try to re-export the extension JSON file, or to create the zip with another software, and to update your original submission post with the new zip file. If that still doesn't work, ask a member of the extension team for help 😉`
})

if(code === "gdevelop-project-file")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Hey ${{ github.event.issue.user.login }}, thanks for your submission! It would seem you confused the extension file with your project file, and thus we cannot find your extension. Make sure you exported the extension itself from the extension editor as a standalone file, zip that standalone extension file, and make sure you did not confuse the "Example" and "Extension" fields while submitting!`
})

if(code === "unknown-json-contents")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Hey ${{ github.event.issue.user.login }}, thanks for your submission! It would seem your JSON file is not a valid GDevelop extension, although it is a JSON file. Please make sure you are exporting with the latest version of GDevelop and that you are not modifying the JSON incorrectly after the export.`
})

if(code === "rule-break")
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `👋 Thanks for your submission! Unfortunately, all submitted extensions have to meet some minimal quality standard - the extension best practices - and our system has found that your extension does not fully comply 😔. You can find all of those rules on [the GDevelop wiki](https://wiki.gdevelop.io/gdevelop5/extensions/best-practices). \n\nThe following issues have been found by the system concerning the respect of those best practices by your extension: \n\`\`\`\n${errors.reduce((acc, error) => `${acc}\n ⟶ ❌ ${error}`, '').slice(1)}\n\`\`\`\nPlease update your original submission post with a new zip file containing your extensions updated to follow those guidelines 🙏`
body: `👋 Hey ${{ github.event.issue.user.login }}, thanks for your submission! Unfortunately, all submitted extensions have to meet some minimal quality standard - the extension best practices - and our system has found that your extension does not fully comply 😔. You can find all of those rules on [the GDevelop wiki](https://wiki.gdevelop.io/gdevelop5/extensions/best-practices). \n\nThe following issues have been found by the system concerning the respect of those best practices by your extension: \n\`\`\`\n${errors.reduce((acc, error) => `${acc}\n ⟶ ❌ ${error}`, '').slice(1)}\n\`\`\`\nPlease update your original submission post with a new zip file containing your extensions updated to follow those guidelines 🙏`
})

if(code !== "success") core.setFailed("Verification of the extension failed!");
Expand All @@ -116,13 +136,20 @@ jobs:
uses: peter-evans/create-pull-request@v5
with:
commit-message: 'Automated Extension submission for issue #${{ github.event.issue.number }}'
committer: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
branch: extension/${{ github.actor }}/${{ github.event.issue.number }}
committer: ${{ github.event.issue.user.login }} <${{ github.event.issue.user.login }}@users.noreply.github.com>
author: ${{ github.event.issue.user.login }} <${{ github.event.issue.user.login }}@users.noreply.github.com>
branch: extension/${{ github.event.issue.user.login }}/${{ github.event.issue.number }}
delete-branch: true
title: '${{ github.event.issue.title }}'
body: ${{ github.event.issue.body }}
labels: ✨ New extension
body: >
${{ github.event.issue.body }}

---

Extension by @${{ github.event.issue.user.login }}
labels: |
✨ New extension
${{(steps.prepare-extension.outputs.reviewed == 'true' && '🔍 Reviewed extension') || '👨‍👩‍👧‍👦 Community extension'}}

- name: Add card to pending review
uses: peter-evans/create-or-update-project-card@v2
Expand All @@ -136,4 +163,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh issue close ${{ github.event.issue.number }}
gh issue comment ${{ github.event.issue.number }} --body "Hi @${{ github.actor }}! 👋 This submission has passed all required tests, and has been moved to a PR as part of our submission pipeline. [You can see the progress of your submission on this page](${{ steps.cpr.outputs.pull-request-url }}). Community submissions are not reviewed by default, so your extension should be added once we've checked that your submission doesn't contain malicious code without further intervention on your part. If you wish for your extension to be reviewed (and thereby moved to the list of reviewed extensions), please follow the instructions written on the [README](https://github.com/GDevelopApp/GDevelop-extensions#get-your-extension-reviewed-extensions). Thanks again for your contribution to GDevelop!"
gh issue comment ${{ github.event.issue.number }} --body "Hi @${{ github.event.issue.user.login }}! 👋 This submission has passed all required tests, and has been moved to a PR as part of our submission pipeline. [You can see the progress of your submission on this page](${{ steps.cpr.outputs.pull-request-url }}). Community submissions are not reviewed by default, so your extension should be added once we've checked that your submission doesn't contain malicious code without further intervention on your part. If you wish for your extension to be reviewed (and thereby moved to the list of reviewed extensions), please follow the instructions written on the [README](https://github.com/GDevelopApp/GDevelop-extensions#get-your-extension-reviewed-extensions). Thanks again for your contribution to GDevelop!"
25 changes: 20 additions & 5 deletions __tests__/auto-pr/auto-pr.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
const { mkdir, rm } = require('fs/promises');
const { verifyExtension } = require('../../scripts/check-single-extension');
const { extractExtension } = require('../../scripts/extract-extension');
const { readdirSync } = require('fs');

const TEMPORARY_MOCK_EXTENSIONS_FOLDER = __dirname + '/mock_extensions_folder';
const TEST_ZIPS_FOLDER = __dirname + '/test-zips';
const TEST_EXTENSIONS_FOLDER = __dirname + '/test-extensions';

/** @param {string} zipName */
const wrappedExtractExtension = async (zipName) =>
const wrappedExtractExtension = async (zipName, reviewed = false) =>
(
await extractExtension(
`${TEST_ZIPS_FOLDER}/${zipName}.zip`,
TEMPORARY_MOCK_EXTENSIONS_FOLDER
)
await extractExtension(`${TEST_ZIPS_FOLDER}/${zipName}.zip`, {
extensionsFolder: TEMPORARY_MOCK_EXTENSIONS_FOLDER,
reviewed,
})
).error;

/** @param {string} extensionName */
Expand Down Expand Up @@ -45,7 +46,19 @@ describe('Auto-pr pipeline', () => {
'too-many-files'
);

// As community extension
expect(await wrappedExtractExtension(`valid-extension`)).toBeUndefined();
expect(
readdirSync(TEMPORARY_MOCK_EXTENSIONS_FOLDER + '/community')
).toContain('UUID.json');

// As reviewed extension
expect(
await wrappedExtractExtension(`valid-extension`, true)
).toBeUndefined();
expect(
readdirSync(TEMPORARY_MOCK_EXTENSIONS_FOLDER + '/reviewed')
).toContain('UUID.json');
});

test(`verifyExtension()`, async () => {
Expand All @@ -57,6 +70,8 @@ describe('Auto-pr pipeline', () => {
expect(await wrappedVerifyExtension(`cri.png`)).toBe('invalid-file-name');
expect(await wrappedVerifyExtension(`RealExtension`)).toBe('invalid-json');
expect(await wrappedVerifyExtension(`Share`)).toBe('rule-break');
expect(await wrappedVerifyExtension(`Fake`)).toBe('unknown-json-contents');
expect(await wrappedVerifyExtension(`ArrayTools`)).toBe('gdevelop-project-file');

expect(await wrappedVerifyExtension(`UUID`)).toBe('success');
expect(await wrappedVerifyExtension(`Clipboard`)).toBe('success');
Expand Down
4 changes: 4 additions & 0 deletions __tests__/auto-pr/test-extensions/community/Fake.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"link": "https://www.youtube.com/watch?v=xvFZjo5PgG0",
"rating": 5
}
Loading