Skip to content

Commit

Permalink
Sc100659/require authtoken to upload (#22)
Browse files Browse the repository at this point in the history
* allow coverage difference to be 0

* check for auth token

* scrape unused mono repo from master

* testing if auth token is undefined

* formatting

* allow null token

* testing with custome comment and no auth token

* change custom message back to diff

* testing with manually setting default

* rm step in build to request different

* testing upload happens with token available

* allow token to be undefined, dont post to endpoint without token

* formatting

* update changelog

* version to 1.02
  • Loading branch information
leah-is-offline authored May 10, 2022
1 parent 75f3365 commit b9db9e0
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 60 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Coverage Upload Action Changelog

## 1.0.2 (May 10, 2022)

- require authtoken to post to endpoint

## 1.0.1 (February 7, 2022)

- Fix getting branch head commit hash on pull request events
Expand Down
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,13 @@ If you have an existing workflow that runs your tests you can just add the `Uplo

## Settings

| Name | Description | Default | Required |
| ---------------- | --------------------------------------------------------------------------------------- | -------------------- | -------- |
| coverageData | The location of the lcov file containing coverage information | `coverage/lcov.info` | No |
| coverageEndpoint | The remote endpoint to upload coverage data to | | No |
| coverageToken | A token to authenticate with the remote endpoint and identify the repo | | No |
| monoRepo | A string (true or false) which indicates whether or not your repository is a mono repo | `false` | No |
| Name | Description | Default | Options | Required |
| ---------------- | ------------------------------------------------------------------------------------------------ | -------------------- | ------------------- | -------- |
| coverageData | The location of the lcov file containing coverage information | `coverage/lcov.info` | | Yes |
| coverageEndpoint | The remote endpoint to upload coverage data to | | | No |
| coverageToken | A token to authenticate with the remote endpoint and identify the repo | | | No |
| customMessage | A string to determine whether the action will receive a coverage difference or a markdown comment| `diff` | `diff` or `message` | Yes |

This action also can accept a markdown comment . Modify your workflow like so:

```yml
customMessage:
description: toggle if the coverageEndpoint expects to respond with the custom message or just the difference
default: 'comment'
required: false
```

## REST API Message Format

Expand Down
4 changes: 0 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ inputs:
description: toggle if the coverageEndpoint expects to respond with the custom message or just the difference
default: 'diff'
required: false
monoRepo:
description: A string (true or false) which indicates whether or not your repository is a mono repo
default: 'false'
required: false
runs:
using: 'node16'
main: 'build/index.js'
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "coverage-upload-action",
"version": "1.0.0",
"version": "1.0.2",
"description": "Parses coverage file and uploads to remote endpoint",
"author": "Neo Financial Engineering",
"license": "MIT",
Expand Down
11 changes: 2 additions & 9 deletions src/get-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { context } from '@actions/github';
import getCoverage from './get-coverage';
import { PRData } from './types';

const getData = async (): Promise<PRData> => {
const authToken = getInput('coverageToken');

const getData = async (authToken?: string): Promise<PRData> => {
const prData: PRData = {
repositoryId: context.payload.repository?.id,
ref: '',
Expand Down Expand Up @@ -48,7 +46,6 @@ const getData = async (): Promise<PRData> => {
}

const coverageData = getInput('coverageData');

const commentData = await getCoverage(coverageData);

prData.coverage.lines = commentData.lines;
Expand All @@ -58,8 +55,4 @@ const getData = async (): Promise<PRData> => {
return prData;
};

const getAllData = (): Record<string, unknown> => {
return context.payload;
};

export { getAllData, getData };
export { getData };
21 changes: 6 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { getInput, setFailed, warning } from '@actions/core';
import { context } from '@actions/github';

import { getAllData, getData } from './get-data';
import { getData } from './get-data';
import makeComment from './make-comment';
import sendDataComment from './send-data';
import sendDataDiff from './send-data-diff';
import testMonoRepo from './test-mono-repo';

const run = async (): Promise<void> => {
try {
const monoRepo = getInput('monoRepo');
const url = getInput('coverageEndpoint');

if (monoRepo === 'true') {
await testMonoRepo(url, getAllData());

return;
}

const prData = await getData();
const authToken = getInput('coverageToken');
const prData = await getData(authToken);

if (!authToken && url) {
warning(
Expand All @@ -33,7 +24,7 @@ const run = async (): Promise<void> => {

const customMessage = getInput('customMessage');

if (url) {
if (url && authToken) {
try {
if (customMessage === 'comment') {
prData.message = await sendDataComment(url, prData);
Expand All @@ -54,9 +45,9 @@ const run = async (): Promise<void> => {
console.log(`Lines percent: ${prData.coverage.lines.percent}`);
console.log(`Functions percent: ${prData.coverage.functions.percent}`);
console.log(`Branches percent: ${prData.coverage.branches.percent}`);
console.log(prData.coverage.lines.diff);
console.log(prData.coverage.functions.diff);
console.log(prData.coverage.branches.diff);
console.log(`Lines percent difference: ${prData.coverage.lines.diff}`);
console.log(`Functions difference: ${prData.coverage.functions.diff}`);
console.log(`Branches difference: ${prData.coverage.branches.diff}`);

if (prData.pullRequest) {
console.log(prData.pullRequest);
Expand Down
13 changes: 0 additions & 13 deletions src/test-mono-repo.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type PRData = {
actor: string;
timestamp: string;
coverage: CommentData;
token: string;
token?: string;
pullRequest?: number;
message?: string;
};
Expand All @@ -36,6 +36,6 @@ export type CoverageJson = {
functionsFound: number;
branchesHit: number;
branchesFound: number;
token: string;
token?: string;
pullRequest?: number;
};

0 comments on commit b9db9e0

Please sign in to comment.