skip to Main Content

Instead of using github API I want to make an auto generated/updated json file of this:

github repo api link
{
  "sha": "asdfadsfasdfadf",
  "url": "https://api.github.com/repos/user/repo/git/trees/asdfasdfadsf",
  "tree": [
    {
      "path": ".gitattributes",
      "mode": "100644",
      "type": "blob",
      "sha": "asdfasdfasdfadf",
      "size": 2518,
      "url": "https://api.github.com/repos/user/repo/git/blobs/asdfasdfadsf"
    },
...

with the use of github actions if possible and generates a json output file like this in the repo:

files.json
{
   "timestamp_created": "01-23-2023 12:34:35",
   "timestamp_updated": "01-23-2023 13:53:23", // if someone made a merge
   "files": [                                  // selected dir from github repo
       {
           "path": "Files/Sample.cs"
           "name": "Sample Script"
       },
   ]
}
...

I have no choice because the github api limit reach was a decent issue of my application that’s why this idea might work to use an auto generated json file from repo that contents all the files of a specific directory in the repository.

2

Answers


  1. Chosen as BEST ANSWER

    I already solved the problem by executing a C# Console Project inside of my repository through dotnet run command since I've noticed that actions can execute commands so I tried to use dotnet and it works.

    name: Run JSON generator with C# File
    
    on:
      push:
        branches:
            - main
      pull_request:
        types:
            - closed
    
    jobs:
      run-csharp-file:
        runs-on: ubuntu-latest
    
        steps:
        - name: Checkout code
          uses: actions/checkout@v2
          with:
            ref: ${{ github.head_ref }}
    
        - name: Setup .NET
          uses: actions/setup-dotnet@v2
          with:
            dotnet-version: '6.0.x'
    
        - name: Run C# file
          run: dotnet run Program.cs --project JSONGenerator/JSONGenerator.csproj > gen.json
    
        - name: Upload artifact
          uses: actions/upload-artifact@v2
          with:
            name: gen.json
            path: gen.json
    

    In my C# code, after adding objects I printed it out as json string, and then this will out as json file base on the command > gen.json

    Console.WriteLine(json);
    

  2. You can try this action to list all the files changed in a PR in json format.

    - uses: jitterbit/get-changed-files@v1
      with:
        # Format of the steps output context.
        # Can be 'space-delimited', 'csv', or 'json'.
        # Default: 'space-delimited'
        format: ''
    

    Source: https://github.com/marketplace/actions/get-all-changed-files#get-all-removed-files-as-json

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search