Skip to content

Commit

Permalink
Minor type renaming
Browse files Browse the repository at this point in the history
- Added content[] to VdTags for eventual propogation to the client
- Unfortunetly need repeated tags because of issue: microsoft/TypeScript#18758 so we have
  2 diffTypes
  • Loading branch information
amilner42 committed Feb 6, 2019
1 parent a785393 commit a5106b2
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 46 deletions.
14 changes: 7 additions & 7 deletions github-app/src/analysis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import R from "ramda"

import { ProtoAppError } from "../error"
import { Diff, parseDiff } from "./diff-parser"
import { AnalyzeFileParams, analyzeFile } from "./tag-parser"
import { DiffWithFiles, analyzeFile } from "./tag-parser"
import { LanguageParserError, extractFileType } from "./languages/index"

/** EXTERNAL TYPES */
Expand Down Expand Up @@ -59,11 +59,11 @@ export const analyzeCommitDiffAndSubmitStatus = async (
return
}

let fileAnalysisParamsArray: AnalyzeFileParams[];
let fileAnalysisParamsArray: DiffWithFiles[];

// Fetch all files needed for analysis
try {
fileAnalysisParamsArray = await Promise.all(analyzableDiff.map(async (fileDiff): Promise<AnalyzeFileParams> => {
fileAnalysisParamsArray = await Promise.all(analyzableDiff.map(async (fileDiff): Promise<DiffWithFiles> => {

let previousFileContent;
let fileContent;
Expand All @@ -72,18 +72,18 @@ export const analyzeCommitDiffAndSubmitStatus = async (

case "modified":
[ previousFileContent, fileContent ] = await retrieveFiles(fileDiff.filePath, fileDiff.filePath)
return { type: "modified", previousFileContent, fileContent, diff: fileDiff }
return { diffType: "modified", previousFileContent, fileContent, diff: fileDiff }

case "renamed":
[ previousFileContent, fileContent ] = await retrieveFiles(fileDiff.filePath, fileDiff.newFilePath)
return { type: "renamed", previousFileContent, fileContent, diff: fileDiff }
return { diffType: "renamed", previousFileContent, fileContent, diff: fileDiff }


case "deleted":
return { type: "deleted", diff: fileDiff }
return { diffType: "deleted", diff: fileDiff }

case "new":
return { type: "new", diff: fileDiff }
return { diffType: "new", diff: fileDiff }
}

}))
Expand Down
6 changes: 3 additions & 3 deletions github-app/src/analysis/languages/cplusplus.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Module for cplusplus-specific parsing functionality

import { VdTag, AnalyzeFileParams } from "../tag-parser"
import { VdTag, DiffWithFiles } from "../tag-parser"

// Parses all VD tags from a cplusplus file.
export const parseVdTags = (params: AnalyzeFileParams): VdTag[] => {
export const parseVdTags = (diffWithFiles: DiffWithFiles): VdTag[] => {

// Parse file according to diff type
switch (params.type) {
switch (diffWithFiles.diffType) {

case "new":
throw new Error("NOT IMPLEMENETED")
Expand Down
4 changes: 2 additions & 2 deletions github-app/src/analysis/languages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import R from "ramda"

import { AnalysisError } from "../index"
import { AnalyzeFileParams, VdTag } from "../tag-parser"
import { DiffWithFiles, VdTag } from "../tag-parser"

// Language parsing imports
import * as cpp from "./cplusplus"
Expand Down Expand Up @@ -70,7 +70,7 @@ export const extractFileType = (filePath: string): Language => {
}

// Parses the tags based on the langauge of the file
export const parseVdTags = (params: AnalyzeFileParams): VdTag[] => {
export const parseVdTags = (params: DiffWithFiles): VdTag[] => {

// TODO what about the case where the language changes on a "rename"?
const language = extractFileType(params.diff.filePath)
Expand Down
12 changes: 6 additions & 6 deletions github-app/src/analysis/languages/java.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
// Module for java-specific parsing functionality

import { VdTag, AnalyzeFileParams } from "../tag-parser"
import { VdTag, DiffWithFiles } from "../tag-parser"

// Parses all VD tags from a java file.
export const parseVdTags = (params: AnalyzeFileParams): VdTag[] => {
export const parseVdTags = (diffWithFiles: DiffWithFiles): VdTag[] => {

// Parse file according to diff type
switch (params.type) {

case "new":
throw new Error("NOT IMPLEMENETED")
switch (diffWithFiles.diffType) {

case "deleted":
throw new Error("NOT IMPLEMENETED")

case "modified":
throw new Error("NOT IMPLEMENETED")

case "new":
throw new Error("NOT IMPLEMENETED")

case "renamed":
throw new Error("NOT IMPLEMENETED")

Expand Down
6 changes: 3 additions & 3 deletions github-app/src/analysis/languages/javascript.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Module for javascript-specific parsing functionality

import { VdTag, AnalyzeFileParams } from "../tag-parser"
import { VdTag, DiffWithFiles } from "../tag-parser"

// Parses all VD tags from a javascript file.
export const parseVdTags = (params: AnalyzeFileParams): VdTag[] => {
export const parseVdTags = (diffWithFiles: DiffWithFiles): VdTag[] => {

// Parse file according to diff type
switch (params.type) {
switch (diffWithFiles.diffType) {

case "new":
throw new Error("NOT IMPLEMENETED")
Expand Down
6 changes: 3 additions & 3 deletions github-app/src/analysis/languages/python.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Module for python-specific parsing functionality

import { VdTag, AnalyzeFileParams } from "../tag-parser"
import { VdTag, DiffWithFiles } from "../tag-parser"

// Parses all VD tags from a python file.
export const parseVdTags = (params: AnalyzeFileParams): VdTag[] => {
export const parseVdTags = (diffWithFiles: DiffWithFiles): VdTag[] => {

// Parse file according to diff type
switch (params.type) {
switch (diffWithFiles.diffType) {

case "new":
throw new Error("NOT IMPLEMENETED")
Expand Down
6 changes: 3 additions & 3 deletions github-app/src/analysis/languages/typescript.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Module for typescript-specific parsing functionality

import { VdTag, AnalyzeFileParams } from "../tag-parser"
import { VdTag, DiffWithFiles } from "../tag-parser"

// Parses all VD tags from a typescript file.
export const parseVdTags = (params: AnalyzeFileParams): VdTag[] => {
export const parseVdTags = (diffWithFiles: DiffWithFiles): VdTag[] => {

// Parse file according to diff type
switch (params.type) {
switch (diffWithFiles.diffType) {

case "new":
throw new Error("NOT IMPLEMENETED")
Expand Down
54 changes: 35 additions & 19 deletions github-app/src/analysis/tag-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { parseVdTags } from "./languages/index"

/** EXTERNAL TYPES */

export type AnalyzeFileParams =
{ type: "modified", previousFileContent: string, fileContent: string, diff: ModifiedFileDiff } |
{ type: "renamed", previousFileContent: string, fileContent: string, diff: RenamedFileDiff } |
{ type: "new", diff: NewFileDiff } |
{ type: "deleted", diff: DeletedFileDiff }
export type DiffWithFiles =
{ diffType: "modified", diff: ModifiedFileDiff, previousFileContent: string, fileContent: string } |
{ diffType: "renamed", diff: RenamedFileDiff, previousFileContent: string, fileContent: string } |
{ diffType: "new", diff: NewFileDiff } |
{ diffType: "deleted", diff: DeletedFileDiff }


/** All possible VD tag types
Expand All @@ -23,9 +23,10 @@ export type VdTagType = "file" | "block" | "function" | "line"

// All tags should have these properties.
export interface BaseTag {
type: VdTagType;
tagType: VdTagType;
vdTagLineNumber: number;
owner: string;
content: string[];
}

// All tags that have line ownership should have these properties.
Expand All @@ -36,22 +37,22 @@ export interface LineOwnershipTag {

// A tag representing documentation ownership of an entire file.
export type VdFileTag = BaseTag & {
type: "file";
tagType: "file";
}

// A tag representing documentation ownership of a function.
export type VdFunctionTag = BaseTag & LineOwnershipTag & {
type: "function";
tagType: "function";
}

// A tag representing documentation ownership of a explicitly specified block.
export type VdBlockTag = BaseTag & LineOwnershipTag & {
type: "block";
tagType: "block";
}

// A tag representing documentation ownership of a single line of code.
export type VdLineTag = BaseTag & LineOwnershipTag & {
type: "line";
tagType: "line";
}

// A review indicates that a certain `VdTag` must be reviewed.
Expand All @@ -62,30 +63,28 @@ export type ReviewType = "new" | "deleted" | "modified"

// All Reviews should have these properties.
export interface BaseReview {
type: ReviewType;
tagType: VdTagType;
reviewType: ReviewType;
tag: VdTag;
}

// A review for a new tag.
export type ReviewNewTag = BaseReview & {
type: "new";
reviewType: "new";
isNewFile: boolean;
content: string[];
}

// A review for a deleted tag.
export type ReviewDeletedTag = BaseReview & {
type: "deleted";
reviewType: "deleted";
isDeletedFile: boolean;
content: string[];
}

/** A review for a modified tag.
Modifications include any/all of the following: changing the tag, changing some code, changing the docs.
*/
export type ReviewModifiedTag = BaseReview & {
type: "existing";
reviewType: "existing";
modifiedTag: boolean;
modifiedCode: boolean;
modifiedDocs: boolean;
Expand All @@ -98,7 +97,24 @@ const VD_TAG = "@VD"
/** EXTERNAL FUNCTIONS */

// Returns all line numbers of @VD tags that need to be approved.
export const analyzeFile = (params: AnalyzeFileParams): Review[] => {
export const analyzeFile = (diffWithFiles: DiffWithFiles): Review[] => {

const vdTags = parseVdTags(diffWithFiles)

switch ( diffWithFiles.diffType ) {

case "new":
throw new Error("NOT IMPLEMENETED YET")

case "deleted":
throw new Error("NOT IMPLEMENETED YET")

case "renamed":
throw new Error("NOT IMPLEMENETED YET")

case "modified":
throw new Error("NOT IMPLEMENETED YET")

} // end switch

throw new Error("NOT IMPLEMENETED YET")
}

0 comments on commit a5106b2

Please sign in to comment.