Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use treeless clone to efficiently retrieve enough history to diff with the --merge-base option. #34

Merged
merged 1 commit into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ jobs:
runs-on: ubuntu-latest

steps:
# Check out a copy of this repository so that we can compute a diff to
# evaluate and load the Action's configuration.
- name: Checkout this repository
uses: actions/checkout@v4

# Run the estimation tool
- name: Run sizeup
# TODO: Replace the version below with your desired version.
#
# For more details please see:
# https://github.com/lerebear/sizeup-action/blob/main/README.md#versioning
uses: lerebear/[email protected]
id: sizeup-action

Expand All @@ -49,23 +46,29 @@ jobs:
# This input is required.
token: "${{ secrets.GITHUB_TOKEN }}"

# Optional arguments that will be forwarded to `git diff` when
# computing the diff to evaluate with this Action.
# Options that will be forwarded to `git diff` when computing the
# diff to evaluate with this workflow.
#
# Defaults to "--ignore-space-change", which ignores lines of the
# diff in which the only change is to the amount of whitespace on the
# line.
git-diff-args: ""
git-diff-options: ""

# Path to a YAML configuration file for this Action that is stored in
# this repository.
# Path to a YAML configuration file for this workflow that is stored
# in this repository.
#
# This input defaults to "", which instructs the Action to use the
# This input defaults to "", which instructs the workflow to use the
# built-in default configuration.
configuration-file-path: ".github/workflows/sizeup/config.yaml"
```
This will use `sizeup` to estimate the reviewability of any pull request opened on your repository using a YAML configuration file found at `.github/workflows/sizeup/config.yaml`. The format of the configuration file is described below.
This will use [`sizeup`](https://github.com/lerebear/sizeup-core) to estimate the reviewability of any pull request opened on your repository using a YAML configuration file found at `.github/workflows/sizeup/config.yaml`. The format of the configuration file is described below.

Please note that the workflow configuration above does not use [`actions/checkout`](https://github.com/actions/checkout). This is because `actions/checkout` does not provide enough options to make a customized `git diff` command maximally efficient. Instead, this Action will perform its own clone, fetch, and checkout operations using the provided `token`.

## Versioning

This Action follows [semantic versioning conventions](https://semver.org), but is still <1.0. Thus, as is common for pre-1.0 software, breaking changes are sometimes introduced in minor version bumps (although patch version bumps will only contain backwards-compatible bug fixes). Please bear this in mind when choosing the version of this Action that you would like to use.

## Configuration

Expand Down
15 changes: 14 additions & 1 deletion __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,31 @@
import * as core from '@actions/core'
import * as main from '../src/main'
import * as initializer from '../src/initializer'
import { Git } from '../src/git'
import * as github from '@actions/github'

function pullRequestEventContext(overrides = {}): object {
return {
eventName: 'pull_request',
repo: {
owner: 'lerebear',
name: 'sizeup-action'
},
payload: {
pull_request: {
base: {
ref: 'main',
repo: {
full_name: 'lerebear/sizeup-action',
name: 'sizeup-action',
owner: {
login: 'lerebear'
}
}
},
head: {
ref: 'topic'
},
labels: [],
number: 1,
user: {
Expand Down Expand Up @@ -69,9 +79,12 @@ describe('action', () => {
// Shallow clone original @actions/github context
const originalContext = { ...github.context }

// Mock cloning the repo
jest.spyOn(Git.prototype, 'clone').mockImplementation(async () => {})

// Mock the diff that we use for evaluation.
jest
.spyOn(initializer, 'fetchDiff')
.spyOn(Git.prototype, 'diff')
.mockImplementation(async () =>
Promise.resolve(
'--- README.md 2023-10-16 16:35:38\n+++ README-AGAIN.md 2023-10-16 16:36:07\n@@ -0,0 +1 @@\n+# Hello, World!'
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ inputs:
token:
description: 'GitHub API token with read permissions for pull requests in this repository.'
required: true
git-diff-args:
git-diff-options:
description: |
Optional custom arguments to forward to `git diff` when retrieving the diff of the pull request that triggered this workflow.
Custom options to forward to `git diff` when retrieving the diff of the pull request that triggered this workflow.
The result of that `git diff` command will be used for evaluation with sizeup.
default: '--ignore-space-change'
configuration-file-path:
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
178 changes: 113 additions & 65 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading