ld-find-code-refs
ld-find-code-refs copied to clipboard
Does Branch Code Reference is being deleted over time?
Scenario:
- Created a PR with new FF and synced reference, now I see in the list of branches
- Merged and deleted branch, it's still available in LD as code reference
Is this ok? What's the suggestion only sync main branch?
@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
-
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.
-
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.