DEV Community

Cover image for Map your Issues!
Giorgio Lasala
Giorgio Lasala

Posted on

Map your Issues!

Hi, I am Giorgio Lasala and this is my submission for Github Actions Hackaton.
This is also my first post on Dev.to !

Submission Category

Wacky Wildcards

How it works

Project is composed of three components:

  • A Github workflow triggered by issue events and powered by free and open-source Github actions
  • A simple Azure Function to receive event and write to Azure CosmosDb
  • A PowerBI Report to show finally issues on world map!

Workflow pipeline

Yaml pipeline uses two opensource Github Actions:

  • octokit/graphql-action: to query about user location info
  • satak/webrequest-action: to post JSON data to Azure Function

When workflow is triggered by a new issue (or comment), the first step

- uses: octokit/graphql-action@v2.x
  id: get_user_info
  with:
    query: |
      query info($owner:String!) { 
        user(login: $owner) {
          location
        }
      }
    owner: ${{ github.actor }}
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

extracts location from user profile, using GraphQL Github API.

Instead second step

- uses: satak/webrequest-action@master
  env:
    USERLOCATION: ${{ steps.get_user_info.outputs.data }}
    USERNAME: ${{ github.actor }}
    REPOSITORY: ${{ github.repository }}
  with:
      url: 'http://0caad210bf6f.ngrok.io/api/ReceiveIssue'
      method: 'POST'
      headers: '{"x-functions-key": "${{ secrets.FUNCTION_KEY }}"}'
      payload: '{ "location": ${{ env.USERLOCATION }}, "repository": "${{ env.REPOSITORY }}", "username": "${{ env.USERNAME }}" }'

creates a complete JSON payload and send it to Azure Function in order to store it in database.

Azure Function

It is a HTTP Trigger Azure Function that receives event from Github pipeline and writes to CosmosDb using OutputBinding.
Azure function must be invoked using a function key, received by x-functions-key HTTP header.


[FunctionName("ReceiveIssue")]
public static async Task<IActionResult> Run(
    [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
    [CosmosDB(
        databaseName: "Github",
        collectionName: "Issues",
        ConnectionStringSetting = "CosmosDBConnection")] IAsyncCollector<Event> eventsOut,
    ILogger log)
{
    log.LogInformation("Received event");

    try
    {
        string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        dynamic data = JsonConvert.DeserializeObject(requestBody);

        string location = data.location.user.location;
        string repos = data.repository;
        string username = data.username;

        var eventObj = new Event()
        {
            Location = location,
            Username = username,
            EventDate = DateTime.Now,
            Repository = repos
        };

        await eventsOut.AddAsync(eventObj);

        return new OkObjectResult("Event inserted");
    }
    catch(Exception ex)
    {
        log.LogError(ex, "Error insert event");
        return new BadRequestObjectResult("Event not valid");
    }
}

PowerBi Report

This is one of first PowerBi report, so I am not skilled about it and any suggestions are welcome!
There is an issue... on published report, data aren't updated in real time (you can find more details on Microsoft Docs and a trick to schedule hourly data refresh).
However using a DirectQuery supported datasource this problem can be overcome.

At the end, report is published on a public website!

Yaml File and Link to Code

You can check out the code on my GitHub Repository

Map your Issues

This repository contains a Github Action workflow triggered on new issues to create a World map of issues location.

How it works

It is composed of three components:

  • A Github workflow triggered by issue events and powered by free and open-source Github actions
  • A simple Azure Function to receive event and write to Azure CosmosDb
  • A PowerBI Report to show finally issues on world map!

Workflow pipeline

Yaml pipeline uses two opensource Actions:

  • octokit/graphql-action: to query about user location info using Github GraphQL API
  • satak/webrequest-action: to post JSON data to Azure Function

In next days (after I will check some stuff) I will publish also PowerBi report on GitHub repository!

Additional Resources / Info

If you like, please add a ⭐ and especially write an issue, so you can pin πŸ“Œ you on map

Nice to have

This is obviously a simple Proof-Of-Concept project developed in some hours, but I think in next days/weeks I will try to improve such as:

⬜ Use DirectQuery Datasource to have near-real time updates (or alternatively develop a complete website using SignalR and Azure Maps or similar)

⬜ Improve Azure-side pipeline to improve scalability (e.g. using Azure Event Hub + data enrichments from other sources)

⬜ Create a shared-world-map of all Github repositories!

⬜ Create IaC script to speed up deployments

⬜ Extract data from issue message, using Text Analysis AI algorithms

βœ… Improve Security with Function Authorization Key

Top comments (0)