List all files changed in a pull request in Git/GitHub

前端 未结 6 1723
执念已碎
执念已碎 2020-12-29 04:58

Is there a way (from the command line) to list the names of all files changed in a PR in Git/GitHub? This would be used to find what tests need to be run in a Travis CI buil

相关标签:
6条回答
  • 2020-12-29 05:24

    Google search sent me here though it is slightly different question.

    This question [details] has command-line. However, I needed the list of files, its ok if I can see in GUI

    Here a way to see list of files in GUI:

    1. open the pull request

    2. click on the [Files changed] tab

      Conversation 0 Commits 3 [Files changed] 8

    3. click on drop down after 'n files' in the below line of [Files changed]

      Changes from all commits v ... [8 files v] ... +638 −266

    (click on the v, drop down, after files in the above line)

    0 讨论(0)
  • 2020-12-29 05:29

    For GitHub specifically, this can be accomplished using the REST API:

    GET /repos/:owner/:repo/pulls/:pull_number/files
    

    You can use one of the GitHub libraries for this purpose.

    0 讨论(0)
  • 2020-12-29 05:30

    Here is the simple method:

    1. Generate below url for POST request https://dev.azure.com/**{OranizationName}**/_apis/Contribution/HierarchyQuery/project/**{ProjectID}**?api-version=5.0-preview.1
    2. Refer this link for any value you need https://docs.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-5.1
    3. Use below Json as a request param {"contributionIds":["ms.vss-code-web.pr-detail-data-provider"],"dataProviderContext":{"properties":{"pullRequestId":{PullRequestID},"repositoryId":"{repositoryId}","sourcePage":{"url":"https://dev.azure.com/{OrganizationName}/{ProjectName}/_git/{RepositoryName}/pullrequest/{PullRequestID}?_a=files"}}}}
    4. Send POST request
    5. Get Count from highlighted property to get the file count for each PR

    6. Create access token in Azure DevOps and use it for authentication 7. Provide Code and Token Administration access to token

    0 讨论(0)
  • 2020-12-29 05:33

    In general, you can list the files changed between any two commits with git diff --name-only :

    How to list only the file names that changed between two commits?

    The problem here seems to be determining the 'merge base'. If all branches originate with master, then you could do:

    git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD master)

    This will show you the changes between the point at which the FETCH_HEAD was branched from master to the current FETCH_HEAD. I tested this locally, and the PR branches are cut from master I believe it should work.

    0 讨论(0)
  • 2020-12-29 05:36

    Chrome console...

    Note: This will break if Github changes the tags/classes/IDs in the page.

    const fileElems = document.querySelectorAll('#files div.file-info a.link-gray-dark');
    const filePaths = [];
    
    for (let a of fileElems) {
        filePaths.push(a.title);
    }
    
    const filePathsStr = filePaths.join('\n');
    console.log(filePathsStr);
    copy(filePathsStr);
    console.log('Copied to the clipboard as well                                                                     
    0 讨论(0)
  • 2020-12-29 05:41

    I couldn't find a way to see just the list of changed files in GitHub (i.e. without the diff and comments), but it can be done with this one-liner in the browser console:

    Array.from(document.getElementsByClassName('js-details-target')).forEach((e) => {e.click();})
    

    This will collapse all the diff blocks leaving only the filenames.

    0 讨论(0)
提交回复
热议问题