write a function to count the number of semicolons in a github repo by downloading the repo by a url without using the git cli in matlab

main.m
function semicolonCount = countSemicolonsInGithubRepo(repoUrl)
% This function takes a url of a Github repository and returns the total count of semicolons in all .m files in the repo
% Usage:
%   semicolonCount = countSemicolonsInGithubRepo('https://github.com/username/repo')
% Arguments:
%   repoUrl: A string containing the URL of the Github repository to be searched
% Returns:
%   semicolonCount: An integer containing the total count of semicolons in all .m files in the repo

% 1. Get the list of all .m files in the repository using the Github REST API
apiUrl = [repoUrl '/contents/'];
apiData = webread(apiUrl);
fileNames = apiData([apiData.type] == "file" & endsWith({apiData.path}, '.m'));
totalSemicolons = 0;

% 2. Download each .m file and count the semicolons in it
for i = 1:length(fileNames)
    fileUrl = fileNames(i).download_url;
    fileData = webread(fileUrl);
    semicolonCount = count(fileData, ';');
    totalSemicolons = totalSemicolons + semicolonCount;
end

semicolonCount = totalSemicolons;
end
1026 chars
26 lines

Explanation:

This function takes a URL of a Github repository as an input and uses the Github REST API to get the list of all .m files in the repository. Then, it downloads each .m file and counts the number of semicolons in it using the count function. Finally, it returns the total count of semicolons in all .m files in the repository.

The webread function is used to communicate with the Github API, and the count function is used to count the number of semicolons in each file.

gistlibby LogSnag