Search code examples
node.jsgithub-api

"since" query parameter for github api not working


I am attempting to use the GitHub API and having trouble getting the correct results back. I would like to use the since query param or preferably even a date range if possible.

It appears that we can request commit hashes from github by specifying the date using the "since" param(Reference: https://docs.github.com/en/rest/apps/apps?apiVersion=2022-11-28#list-installations-for-the-authenticated-app). Below is my code:

let gitCommitHashes = [];
let gitCommitDates = [];

axios.get(
        "https://api.github.com/repos/myuser/myreponame/commits?path=filename.xml&page=1&per_page=5&since=2020-06-06T00:00:00Z",
        {
          headers: {
                "Access-Control-Allow-Origin" : "*",
                "content-type": "text/plain",
                "Authorization": `Bearer `+BEARER_TOKEN,
                "Access-Control-Allow-Methods": "POST, GET, OPTIONS, DELETE, PUT"
                }   
        }
      )
      .then((response) => {                 
         // console.log(response);                
          for(var i=0;i<response["data"].length;i++){
                      // console.log(response["data"][i].sha);               
              gitCommitDates.push(response["data"][i]["commit"]["author"].date);              
              //console.log(response["data"][i]["commit"]["author"].date);              
              gitCommitHashes.push(response["data"][i].sha);               
          }
          for(var i=0;i<gitCommitHashes.length;i++){             
                console.log(i+"------>"+gitCommitHashes[i])
                console.log("gitCommitDates: "+gitCommitDates[i])
          }
        },
        (error) => {
        // var status = error.response.status
        }
      );        

I do get data back, however, I get the latest commits. The gitCommitDates prints todays date and the hashes returned are the latest one despite of me passing in the date 2020-06-06T00:00:00Z in the since param. It appears that github is ignoring the since param completely. I have also attempted the approach give over here(https://www.youtube.com/watch?v=b0W7SHHDc28). But this also does not give me the correct results. I also do not quite understand the page and per_page params. I dont know how per_page "100" as a number makes sense. What does 100 results per page even mean for commits? What am I doing wrong here?? I am totally out of ideas. I apologize if have any editing mistakes in my post.


Solution

  • It seems that the since parameter is for notifications, you should be able to use until for commits. Source