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

Set up application labelling and commenting #924

Merged
merged 10 commits into from
Mar 28, 2024

Conversation

jodyheavener
Copy link
Member

@jodyheavener jodyheavener commented Mar 26, 2024

/dev/web/developer.1password.com/-/issues/1065

Summary

We are working on improvements to the 1Password for Open Source program. This PR continues from #918 and sets up application labelling and commenting from the bot account based on the application's status and validity.

What's changed?

The main change here is setting up what our "bot" account does in response to an issue. Now, when an application issue is opened or updated, we do the following:

  • Get the status of the issue - is it closed? Was it previously valid or invalid? Has it already been approved?
  • Use the status to write a comment on the issue. This is determined both by the current status, as well as the validity of the application. If the issue is closed or the application is already approved, we can't do anything. If the issue is not valid, report that. If the issue is valid, report that - get specific if it was previously valid. In these latter cases, also print the data we're going to store once the application is approved.

Additionally the following was changed:

  • Updates how the application renders its formatted problem strings
  • Adds a handful of test issues

Testing

There are no new unit/integration tests just yet (but there will be), but there are several updates to the manual testing flow to help debug and validate the application processor, like the last issue. Here's how to use it:

git checkout jh/application-label-comment
make install_deps && make build_processor
./processor review --test-issue <issue-name> 

This command will print the application input it received and the parsed data.

Example output
[DEBUG] Using test issue 'valid-project'
[DEBUG] Skipping GitHub Init
[DEBUG] Parsed input data:
{
        "Account URL": "testdb.1password.com",
        "Additional comments": "Thank you!",
        "Age confirmation": "- [X] Yes, this project is at least 30 days old",
        "Can we contact you?": "- [X] Yes, you may contact me",
        "Email": "[email protected]",
        "Event application": "- [ ] Yes, this application is for an event",
        "Homepage URL": "https://github.com/wendyappleed/test-db",
        "License URL": "https://github.com/wendyappleed/test-db/blob/main/LICENSE.md",
        "License type": "MIT",
        "Name": "Wendy Appleseed",
        "Non-commercial confirmation": "- [X] No, this account won't be used for commercial activity",
        "Number of team members/core contributors": "1",
        "Profile or website": "https://github.com/wendyappleseed/",
        "Project name": "TestDB",
        "Project role": "Core Maintainer",
        "Repository URL": "https://github.com/wendyappleed/test-db",
        "Short description": "TestDB is a free and open source, community-based forum software project.",
        "Team application": "- [ ] Yes, this application is for a team"
}
[DEBUG] Application data:
{
        "account": "testdb.1password.com",
        "project": {
                "name": "TestDB",
                "description": "TestDB is a free and open source, community-based forum software project.",
                "contributors": 1,
                "home_url": "https://github.com/wendyappleed/test-db",
                "repo_url": "https://github.com/wendyappleed/test-db",
                "license_type": "MIT",
                "license_url": "https://github.com/wendyappleed/test-db/blob/main/LICENSE.md",
                "is_event": false,
                "is_team": false
        },
        "applicant": {
                "name": "Wendy Appleseed",
                "email": "[email protected]",
                "role": "Core Maintainer",
                "id": 38230737
        },
        "can_contact": true,
        "issue_number": 6,
        "created_at": "2023-07-12T19:49:35Z"
}

In addition to this information this will output the automated bot comment's message, as well as any labels being added or removed.

The following test issues are available:

valid-project

./processor review --test-issue valid-project

This is a valid application for a project. It will result in the status: reviewing label being added, and a helpful comment about what's next.

Bot comment

✅ Your application is valid

Application data...
{
        "account": "testdb.1password.com",
        "project": {
                "name": "TestDB",
                "description": "TestDB is a free and open source, community-based forum software project.",
                "contributors": 1,
                "home_url": "https://github.com/wendyappleed/test-db",
                "repo_url": "https://github.com/wendyappleed/test-db",
                "license_type": "MIT",
                "license_url": "https://github.com/wendyappleed/test-db/blob/main/LICENSE.md",
                "is_event": false,
                "is_team": false
        },
        "applicant": {
                "name": "Wendy Appleseed",
                "email": "[email protected]",
                "role": "Core Maintainer",
                "id": 38230737
        },
        "can_contact": true,
        "issue_number": 6,
        "created_at": "2023-07-12T19:49:35Z"
}

Thanks for applying! Next step: our team will review your application and may have follow-up questions. You can still make changes to your application and we'll process it again.

The valid-team and valid-event test issues will have a similar output.

valid-project-reviewing

./processor review --test-issue valid-project-reviewing

This is a valid application, where the application was previously valid. This will not result in any label changes.

Bot comment

👍 Application still valid

Application data...
{
        "account": "testdb.1password.com",
        "project": {
                "name": "TestDB",
                "description": "TestDB is a free and open source, community-based forum software project.",
                "contributors": 1,
                "home_url": "https://github.com/wendyappleed/test-db",
                "repo_url": "https://github.com/wendyappleed/test-db",
                "license_type": "MIT",
                "license_url": "https://github.com/wendyappleed/test-db/blob/main/LICENSE.md",
                "is_event": false,
                "is_team": false
        },
        "applicant": {
                "name": "Wendy Appleseed",
                "email": "[email protected]",
                "role": "Core Maintainer",
                "id": 38230737
        },
        "can_contact": true,
        "issue_number": 6,
        "created_at": "2023-07-12T19:49:35Z"
}

We've processed your updated application and everything still looks good.

valid-project-closed

./processor review --test-issue valid-project-closed

This is a valid application for a project, but the issue for the application is already closed and therefor cannot be modified in any way - processing aborted. This will not result in any label changes.

Bot comment

Oops! This application is closed can no longer be processed. If this is an error, please reach out to [email protected].

valid-project-approved

./processor review --test-issue valid-project-approved

This is a valid application for a project, but it was already approved and therefor cannot be modified in any way - processing aborted. This will not result in any label changes.

Bot comment

Oops! This application has been updated but has already been approved and can no longer be processed. If this is an error, please reach out to [email protected].

invalid-examples-1

./processor review --test-issue invalid-examples-1

This is an application that contains validation errors. It will result in the status: invalid label being added, and a comment that contains the errors that need to be addressed.

Bot comment

❌ Your application needs some work

Application data...
{
        "account": "foo",
        "project": {
                "name": "TestDB 🎁",
                "description": "TestDB is a free and open source, community-based forum software project.",
                "contributors": 0,
                "home_url": "@wendyappleed",
                "repo_url": "https://github.com/wendyappleed/test-db",
                "license_type": "MIT",
                "license_url": "https://github.com/wendyappleed/test-db/blob/main/LICENSE.md",
                "is_event": false,
                "is_team": false
        },
        "applicant": {
                "name": "Wendy Appleseed",
                "email": "[email protected]",
                "role": "Lead Dev",
                "id": 38230737
        },
        "can_contact": true,
        "issue_number": 6,
        "created_at": "2023-07-12T19:49:35Z"
}

The following issues need to be addressed:

  • Application title is missing project name
  • Account URL is invalid 1Password account URL
  • Non-commercial confirmation must be checked
  • Project name cannot contain emoji characters
  • Number of team members/core contributors could not be parsed into a number
  • Homepage URL is an invalid URL

The invalid-empty-body and invalid-no-responses test issues will have a similar output.

@jodyheavener jodyheavener added the 2024-program-updates Updates to the open source program in 2024 label Mar 26, 2024
@jodyheavener jodyheavener force-pushed the jh/application-label-comment branch 2 times, most recently from fda14fb to 8aa1341 Compare March 26, 2024 18:27
Copy link

@schneedotdev schneedotdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

I ran through your changes and have validated everything on my end.

Copy link

@michaelAbon1p michaelAbon1p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I love the structure of this. I have one idiomatic suggestion. I don't think that the response messages fit with our tone. I've tried to link to the 1Password Style Guide or the base Apple Style Guide upon which ours is built. My intent here is to make it sound like we're all writing in one voice. Feel free to disagree. Ping me when you want me to take another look!

script/reviewer.go Outdated Show resolved Hide resolved
script/reviewer.go Outdated Show resolved Hide resolved
script/reviewer.go Outdated Show resolved Hide resolved
script/reviewer.go Outdated Show resolved Hide resolved
script/reviewer.go Outdated Show resolved Hide resolved
script/reviewer.go Outdated Show resolved Hide resolved
func (r *Reviewer) createComment(status Status) {
title := ""
body := ""
details := fmt.Sprintf("<details>\n<summary>Application data...</summary>\n\n```json\n%s\n```\n</details>", r.application.GetData())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second look here... you're making a GitHub comment using untrusted input from our users. What's to prevent them from adding their own HTML or XSS attacks here? Which user is making these comments and could be hijacked? I don't think that GitHub supports slash commands like GitLab (where they could force your bot to /approve the issue), but am I missing something there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub has extremely strict markdown sanitization rules (otherwise any Issue/PR/Readme could XSS you). GH doesn't directly support any slash commands that perform actions, however, if we implemented chat/slash commands with GH Actions down the road, yes this could be a problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great callout! By and large json.MarshalIndent, used by the GetData method, escapes <, >, & and produces valid JSON, reducing the chances of breaking out of the printed JSON.

That said, I've hardened this even further by parsing all input data as Markdown into HTML, then retrieving only the text content of the HTML. This will help:

  1. Protect us against Markdown syntax being used to break out of the JSON. After all, the JSON is itself being printed inside of a Markdown code block in the issue comment, so a user might have tried to use three backticks to end the code block.
  2. Protect consumers of this data down the road are better protected if they directly render one of the JSON values (like the project description).

Which user is making these comments and could be hijacked?

We are employing a bot account to make these comments. A PAT for that account is stored as a secret on this repository and passed to the script when the workflow is invoked. Absent this PAT the script will bail.

I don't think that GitHub supports slash commands like GitLab (where they could force your bot to /approve the issue), but am I missing something there?

On the approval side, the workflow to approve and commit the data to the repository is only invoked when the status: approved label is added to the issue, and labels can only be added by a collaborator on the repository. Only AgileBits employees can be collaborators on the repository.

Copy link
Member

@MNThomson MNThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after those few comments

Comment on lines 84 to 90
if status == Invalid && r.application.IsValid() {
if err := r.gitHub.RemoveIssueLabel(LabelStatusInvalid); err != nil {
r.printErrorAndExit(
fmt.Errorf("could not remove issue label '%s': %s", LabelStatusInvalid, err.Error()),
)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not move this block to line 93 where it is also inside the if r.application.IsValid() block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch 👍

Comment on lines 56 to 57
// TODO: replace FILE_NAME with Application.FileName once available
dataPath := fmt.Sprintf("https://github.com/1Password/1password-teams-open-source/blob/main/data/%s", "FILE_NAME")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO for this PR or for the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future, once #925 is merged

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: that PR was merged so I've updated!

}
} else {
title = "### ❌ Your application is invalid"
body = fmt.Sprintf("\n\n%s\n\nOur automated pre-checks have detected the following issues:\n\n%s", details, r.application.RenderProblems())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps some sort of "Please fix these problems by updating the PR" language would be helpful

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one. Updated to add:

Update this issue to correct these problems and we’ll automatically re-evaluate your application.

@jodyheavener jodyheavener force-pushed the jh/application-label-comment branch from 87b528d to 26f627a Compare March 28, 2024 18:02
Copy link

@michaelAbon1p michaelAbon1p left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks for being so open to feedback here. The code looks good to me at this point.

@jodyheavener jodyheavener merged commit 14c4961 into program-updates Mar 28, 2024
1 check passed
@jodyheavener jodyheavener deleted the jh/application-label-comment branch April 2, 2024 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2024-program-updates Updates to the open source program in 2024
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants