publisher

package module
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 12 Imported by: 0

README

Test

OneReport Changeset Publisher

This is a command line tool that publishes meta changesets to OneReport.

Here is an example meta changeset:

{
  "remote": "git@github.com:MyOrg/my-project.git",
  "parentShas": [
    "400a62e39d39d231d8160002dfb7ed95a004278b"
  ],
  "sha": "f7d967d6d4f7adc1d6657bda88f4e976c879d74c",
  "loc": 9841,
  "files": 73,
  "changes": [
    {
      "fromPath": "858458ace7ba8e65ef6427310bd96db9cbacc26d",
      "toPath": "d45df6aad2a7e9dc7ff0309d1a916f0d75dcad7a",
      "lineMappings": [
        [10, 11],
        [11, 12],
        [12, -1],
        [-1, 10]
      ]
    }
  ]
}

The lineMappings array is a list of 0-indexed line numbers that have changed, using a [leftLineNumber, rightLineNumber] mapping. -1 means the line was not present. See lhdiff for more details.

Note that the payload does not include any source code. Even fromPath and toPath areanonymized. This can be turned off with the -use-paths option:

{
  "remote": "git@github.com:MyOrg/my-project.git",
  "parentShas": [
    "400a62e39d39d231d8160002dfb7ed95a004278b"
  ],
  "sha": "f7d967d6d4f7adc1d6657bda88f4e976c879d74c",
  "loc": 9841,
  "files": 73,
  "changes": [
    {
      "fromPath": "testdata/b.txt",
      "toPath": "testdata/c.txt",
      "lineMappings": [
        [10, 11],
        [11, 12],
        [12, -1],
        [-1, 10]
      ]
    }
  ]
}

Installation

Download an executable from the releases page.

Command Line

$ one-report-changeset-publisher --help

Usage of one-report-changeset-publisher:
  -dry-run
        Do not publish, only print
  -from-rev string
        From git revision (default is the single parent of to-rev)
  -organization-id string
        OneReport organization id
  -password string
        OneReport password
  -remote string
        Git remote (default is the origin remote in .git/config)
  -to-rev string
        To git revision (default is the HEAD revision)
  -url string
        OneReport url (default "https://one-report.vercel.app")
  -username string
        OneReport username

Configuration

Excluding / Including files

Files that have no impact on test results should be excluded from the published changeset.

  • .onereportignore specifies files to exclude
  • .onereportinclude specifies files to include

Both files follow the .gitignore pattern format

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountFeatures added in v0.0.7

func CountFeatures(repo *git.Repository, tree *git.Tree, exclude *ignore.GitIgnore, include *ignore.GitIgnore, countLines bool) (int, int, error)

CountFeatures counts how many lines of code, and how many files there are.

func MakeRequest

func MakeRequest(changeset *MetaChangeset, organizationId string, baseUrl string, username string, password string) (*http.Request, error)

func Publish

func Publish(changeset *MetaChangeset, organizationId string, baseUrl string, username string, password string) (string, error)
Example
changeset := &MetaChangeset{
	Remote:   "some-remote",
	UnixTime: 1644410531,
	OldShas:  []string{"aaa"},
	Sha:      "bbb",
	Changes:  make([]Change, 0),
	Loc:      9876,
	Files:    31,
}
req, err := MakeRequest(changeset, "1CCC7924-051C-496E-8467-D494C1C37B2A", "https://host.com", "anyone", "secret")
if err != nil {
	fmt.Println(err.Error())
	return
}
res := httptest.NewRecorder()

ChangesetHandler := func(res http.ResponseWriter, req *http.Request) {
	txt, err := httputil.DumpRequest(req, true)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	dumpedReq := strings.ReplaceAll(string(txt), "\r\n", "\n")
	fmt.Print(dumpedReq)
}
ChangesetHandler(res, req)
Output:

POST /api/organization/1CCC7924-051C-496E-8467-D494C1C37B2A/changeset HTTP/1.1
Host: host.com
Authorization: Basic YW55b25lOnNlY3JldA==
Content-Type: application/vnd.smartbear.onereport.changeset.v1+json

{
  "remote": "some-remote",
  "unixTime": 1644410531,
  "oldShas": [
    "aaa"
  ],
  "sha": "bbb",
  "changes": [],
  "loc": 9876,
  "files": 31
}

Types

type Change

type Change struct {
	OldPath      string  `json:"oldPath"`
	NewPath      string  `json:"newPath"`
	LineMappings [][]int `json:"lineMappings"`
}

type MetaChangeset added in v0.0.7

type MetaChangeset struct {
	Remote   string   `json:"remote"`
	UnixTime int64    `json:"unixTime"`
	OldShas  []string `json:"oldShas"`
	Sha      string   `json:"sha"`
	Changes  []Change `json:"changes"`
	// The total number of lines of code in Sha (filtered by .onereportinclude and .onereportexluce
	Loc int `json:"loc"`
	// The total number of files in Sha (filtered by .onereportinclude and .onereportexluce
	Files int `json:"files"`
}

func MakeMetaChangeset added in v0.0.7

func MakeMetaChangeset(
	oldSha string,
	sha string,
	usePaths bool,
	remote string,
	repo *git.Repository,
	exclude *ignore.GitIgnore,
	include *ignore.GitIgnore,
	includeLines bool,
) (*MetaChangeset, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL