flagsmith icon indicating copy to clipboard operation
flagsmith copied to clipboard

Github Integration

Open dabeeeenster opened this issue 3 years ago • 1 comments

This probably will need splitting up into several issues and an overriding milestone

Overview

This feature enables you to see the state of a Flagsmith flag within an associated Github Issue/PR

image

Version 1

Allow Flagsmith users to connect a Github Issue/Pull Request with a Flagsmith flag. Once connected, a Flagsmith Github App/Bot will create and update a comment against the issue showing the state of the Flag in each Flagsmith environment

Version 2

Allow users to enable/disable feature states by clicking the checkboxes. This issue currently only specs Version 1.

Auth

Create a Github Application. Question of whether we should use a Github App or an OAuth app - https://docs.github.com/en/developers/apps/getting-started-with-apps/differences-between-github-apps-and-oauth-apps. Current thinking is use a Github app as that is most common for other apps of this nature.

Flagsmith users will need to give the Github Application permission over their account.

Connect Flag with Issue/PR

Once Auth is done, allow users to paste a Github Issue/PR URL into a Flag Settings page field. Store this against the Feature API model object.

Write a comment

Once URL is pasted, create a comment against the Issue/PR containing:

  • The Flagsmith Feature Name
  • For all Environments, show a checkbox and codeblock text field showing the enabled state and the string value if there is one
  • A sig at the bottom of the comment saying that the comment was generated by a Flagsmith bot with links to the docs

Record the Github ID of the comment against the Feature in Flagsmith so that we can update it on later feature state events.

If the write fails due to lack of permission, feed that back to the user. If the write succeeds, show a green tick next to the issue url.

Update the comment

Whenever the feature_state of the connected feature changes state, update the connected Github comment

Things to consider

Do we want to make this a more generic solution so that we could do similar with e.g. Gitlab/Jira etc?

dabeeeenster avatar Jul 05 '22 09:07 dabeeeenster

I think there will be quite a lot of API work to get this started and workable, so I think it's best to assign to me when we get to this point.

If it helps this is how I implemented the read side of the POC since we're excluding updating feature states from GitHub

  • https://github.com/Flagsmith/webhook-poc/blob/main/pages/api/flagsmith-webhook.ts the flagsmith webhook gets the associated feature and either creates / edits a comment
  • This generates comment text based on feature state values https://github.com/Flagsmith/webhook-poc/blob/main/utils/github/create-comment-text.ts
  • API integration to create a comment https://github.com/Flagsmith/webhook-poc/blob/main/utils/github/api/create-comment.ts
  • API integration to edit a comment https://github.com/Flagsmith/webhook-poc/blob/main/utils/github/api/edit-comment.ts

kyle-ssg avatar Jul 05 '22 11:07 kyle-ssg