@@ -3,14 +3,16 @@ permissions:
33 contents : read
44
55on :
6+ pull_request :
67 schedule :
78 - cron : ' 0 0 * * *' # Runs daily at midnight UTC
89 workflow_dispatch :
910
1011env :
1112 EXCLUDE_PATTERNS : node_modules,venv,.git,cache,build,htmlcov,docs,.json,tests
12- FLAGSMITH_EDGE_API_URL : https://edge.api.flagsmith.com
13- FLAGSMITH_ENVIRONMENT_KEY : ENktaJnfLVbLifybz34JmX
13+ FLAGSMITH_ADMIN_API_URL : https://api.flagsmith.com
14+ FLAGSMITH_SERVER_KEY : ${{ secrets.FLAGSMITH_SERVER_KEY }}
15+ FLAGSMITH_PROJECT_ID : 12
1416 PYTHON_REQUESTS_VERSION : ' 2.32.4'
1517 PYTHON_VERSION : ' 3.13'
1618
@@ -84,10 +86,17 @@ jobs:
8486 yield feature_name, str(path), line_number
8587 # TODO: Add more sophisticated matching, e.g. feature names defined as constants
8688
89+ def retrieve_feature_names() -> list[str]:
90+ """Fetch feature names from the Flagsmith API."""
91+ response = requests.get( # TODO: Make better use of pagination
92+ f"${{ env.FLAGSMITH_ADMIN_API_URL }}/api/v1/projects/${{ env.FLAGSMITH_PROJECT_ID }}/features/?page_size=1000",
93+ headers={"Authorization": f"Token ${{ env.FLAGSMITH_SERVER_KEY }}"},
94+ )
95+ response.raise_for_status()
96+ return sorted(feature["name"] for feature in response.json()["results"])
97+
8798 # Fetch visible features
88- all_flags = requests.get(f"${{ env.FLAGSMITH_EDGE_API_URL }}/api/v1/flags", headers={"X-Environment-Key": "${{ env.FLAGSMITH_ENVIRONMENT_KEY }}"}).json()
89- feature_names = sorted([flag["feature"]["name"] for flag in all_flags])
90- print("Feature names:", feature_names)
99+ feature_names = retrieve_feature_names()
91100
92101 # Find code references
93102 code_references = [
@@ -102,8 +111,11 @@ jobs:
102111 EOF
103112
104113 - name : Display code references
105- shell : python
106114 run : |
115+ uv run - <<EOF
116+ # /// script
117+ # requires-python = "==${{ env.PYTHON_VERSION }}"
118+ # ///
107119 import json
108120 from collections import defaultdict
109121
@@ -122,6 +134,35 @@ jobs:
122134 print(f"\nFeature: {feature_name}")
123135 for file_path, line_number in references:
124136 print(f" - {file_path}:{line_number}")
137+ EOF
125138
126- # TODO
127- # - name: Upload code references
139+ - name : Upload code references
140+ run : |
141+ uv run - <<EOF
142+ # /// script
143+ # requires-python = "==${{ env.PYTHON_VERSION }}"
144+ # dependencies = ["requests==${{ env.PYTHON_REQUESTS_VERSION }}"]
145+ # ///
146+ import json
147+ import os
148+ import requests
149+
150+ code_references = json.loads('''${{ steps.collect.outputs.code_references }}''')
151+ if not code_references:
152+ print("No code references to upload.")
153+ exit(0)
154+
155+ response = requests.post(
156+ # f"${{ env.FLAGSMITH_ADMIN_API_URL }}/api/v1/projects/${{ env.FLAGSMITH_PROJECT_ID }}/code-references/",
157+ # headers={"Authorization": f"Token ${{ env.FLAGSMITH_SERVER_KEY }}"},
158+ "https://mocktarget.apigee.net/echo",
159+ headers={"Authorization": f"Api-Key beware-the-hacker"},
160+ json={
161+ "repository_url": "${{ github.server_url }}/${{ github.repository }}",
162+ "revision": "${{ github.sha }}",
163+ "code_references": code_references,
164+ },
165+ )
166+ response.raise_for_status()
167+ print("Code references uploaded successfully.")
168+ EOF
0 commit comments