I have a Azure DevOps Function which creates a new team in devOps. I'm extending the code to create Repositories and Files and want to have the different parts divided into methods to have it more streamlined.
I would really appreciate it if someone can guide me how I can create methods inside an Azure function and call them as I'm quiet new to C#.
I am using Visual Studio with .NET Core 3.0.
Here is the code so far:
[FunctionName("Function2")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req)
{
var PAT = "";
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(
ASCIIEncoding.ASCII.GetBytes(
string.Format("{0}:{1}", "", PAT))));
// Create Team
var teambody = new
{
name = "myteamname",
};
//Connecting to the DevOps REST API
var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"https://dev.azure.com/{}/_apis/projects/{}/teams?api-version=6.0");
requestMessage.Content = new StringContent(JsonConvert.SerializeObject(teambody), Encoding.UTF8, "application/json");
//Reading Server Response
using (HttpResponseMessage response = await client.SendAsync(requestMessage))
{
if (!response.IsSuccessStatusCode)
{
response.EnsureSuccessStatusCode();
}
return req.CreateResponse(HttpStatusCode.Created,"Teams created successfully!");
}
// Create Repository
// Create Files
}
}