public async Task UpdateRepo()

in Webapp/SDAF/Controllers/RestHelper.cs [130:169]


        public async Task UpdateRepo(string path, string content)
        {
            string getUri = $"{collectionUri}{project}/_apis/git/repositories/{repositoryId}/refs/?filter=heads/{branch}";
            string postUri = $"{collectionUri}{project}/_apis/git/repositories/{repositoryId}/pushes?api-version=5.1";
            string ooId;

            using HttpResponseMessage response = client.GetAsync(getUri).Result;
            string responseBody = await response.Content.ReadAsStringAsync();
            HandleResponse(response, responseBody);

            ooId = JsonDocument.Parse(responseBody).RootElement.GetProperty("value")[0].GetProperty("objectId").GetString();

            // Dynamically retrieve path
            string pathBase = await GetVariableFromVariableGroup(sdafGeneralId, "SDAF-General", "Deployment_Configuration_Path");
            path = pathBase + path;

            // Create request body
            Refupdate refUpdate = new()
            {
                name = $"refs/heads/{branch}",
                oldObjectId = ooId
            };
            GitRequestBody requestBody = new()
            {
                refUpdates = new Refupdate[] { refUpdate },
            };
            StringContent editContent = Helper.CreateHttpContent("edit", path, content, requestBody);

            // try to edit file (if it exists)
            HttpResponseMessage editResponse = await client.PostAsync(postUri, editContent);

            // add file on unsuccessful edit (because it does not exist)
            if (!editResponse.IsSuccessStatusCode)
            {
                StringContent addContent = Helper.CreateHttpContent("add", path, content, requestBody);
                HttpResponseMessage addResponse = await client.PostAsync(postUri, addContent);
                string addResponseBody = await addResponse.Content.ReadAsStringAsync();
                HandleResponse(addResponse, addResponseBody);
            }
        }