launchdarkly / ld-find-code-refs

Build tool for automatically sending feature flag code references to LaunchDarkly
https://launchdarkly.com
Other
46 stars 34 forks source link

Does Branch Code Reference is being deleted over time? #432

Open rkhaslarov opened 7 months ago

rkhaslarov commented 7 months ago

Scenario:

Is this ok? What's the suggestion only sync main branch?

jazanne commented 7 months ago

@rkhaslarov thank you for raising this issue. For some time we have had an ongoing issue where branches in LD are not automatically cleaned up when they are deleted from your repo.

I have a few recommendations for running code references

  1. If you don't need to look at non-default branch references within the LD application (this page) https://docs.launchdarkly.com/home/code/code-references#using-code-references, then I would recommend only running THIS tool on the main branch. We have a pull-request specific version of the tool that is great for running on branches and can be found here: https://github.com/launchdarkly/find-code-references-in-pull-request. It doesn't save information to the LD, but does detect flag changes within the PR diff itself.

  2. If you do have a need to view and store branch code references in LD for non-default branches, you can workaround the issue by calling the delete branch api directly. If you are using github actions, here's an example workflow you can use:

name: Delete code references branch
on: delete

jobs:
  branch-delete-tasks:
    runs-on: ubuntu-latest
    steps:
      - name: Delete branch
        if: ${{ github.event.ref_type == 'branch' }}
        env:
          LD_ACCESS_TOKEN: ${{ secrets.LD_ACCESS_TOKEN }}
          LD_BASE_URI: https://app.launchdarkly.com
        run: |
          echo "Deleting branch ${{ github.event.ref }}"
          curl -i -XPOST "$LD_BASE_URI/api/v2/code-refs/repositories/${{github.event.repository.name}}/branch-delete-tasks" \
          -H 'Content-Type: application/json' \
          -H "Authorization: $LD_ACCESS_TOKEN" \
          -d '[
            "${{ github.event.ref }}"
          ]'

I'm sorry for any inconvenience. Please let me know if this addresses your issue.