Skip to content

Commit b91bd77

Browse files
committed
cleanup
1 parent 367814a commit b91bd77

File tree

6 files changed

+19
-36
lines changed

6 files changed

+19
-36
lines changed

src/commands/action/core/classes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/classes.py
12
import { components } from '@socketsecurity/sdk/types/api'
23

34
type IntroducedBy = [string, string][]

src/commands/action/core/github.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/github.py
12
import { Octokit } from '@octokit/rest'
23
import { Comment } from './classes'
34
import { SCMComments, SocketComments } from './scm_comments'
@@ -29,9 +30,12 @@ export class GitHub {
2930
return this.prNumber ? 'diff' : 'main'
3031

3132
case 'pull_request':
32-
// Provided by github.event.action, add this code below to GitHub action
33-
// if: github.event_name == 'pull_request'
34-
// run: echo "EVENT_ACTION=${{ github.event.action }}" >> $GITHUB_ENV
33+
// This env variable needs to be set in the GitHub action.
34+
// Add this code below to GitHub action:
35+
// - steps:
36+
// - name: Get PR State
37+
// if: github.event_name == 'pull_request'
38+
// run: echo "EVENT_ACTION=${{ github.event.action }}" >> $GITHUB_ENV
3539
const eventAction = process.env['EVENT_ACTION']
3640

3741
if (!eventAction) {
@@ -82,7 +86,6 @@ export class GitHub {
8286
}: {
8387
commentId: number
8488
}): Promise<boolean> {
85-
// Fetch reactions for the specified comment
8689
const { data } = await this.octokit.reactions.listForIssueComment({
8790
owner: this.owner,
8891
repo: this.repo,

src/commands/action/core/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/__init__.py
12
import { SocketSdk } from '@socketsecurity/sdk'
23
import { Diff, FullScan, Issue, Package, Purl } from './classes'
34
import type { components, operations } from '@socketsecurity/sdk/types/api.d.ts'
@@ -27,7 +28,6 @@ export class Core {
2728
this.files = []
2829
}
2930

30-
// OK
3131
async getSbomData({
3232
fullScanId
3333
}: {
@@ -54,15 +54,14 @@ export class Core {
5454
return sbomArtifacts
5555
}
5656

57-
// OK
5857
async createFullScan({
5958
params
6059
}: {
6160
params: Omit<operations['CreateOrgFullScan']['parameters']['query'], 'repo'>
6261
}): Promise<FullScan> {
6362
const orgFullScanResponse = await this.socket.createOrgFullScan(
6463
this.owner,
65-
// pull_request is of type number but URLSearchParams will convert it to a string
64+
// Ignoring because pull_request is of type number but URLSearchParams will convert it to a string
6665
// @ts-ignore
6766
new URLSearchParams({ repo: this.repo, ...params }),
6867
this.files
@@ -80,7 +79,6 @@ export class Core {
8079
return fullScan
8180
}
8281

83-
// OK
8482
getSourceData({
8583
pkg,
8684
packages
@@ -114,7 +112,6 @@ export class Core {
114112
return introducedBy
115113
}
116114

117-
// OK
118115
createPurl({
119116
packageId,
120117
packages
@@ -140,7 +137,6 @@ export class Core {
140137
return { purl, pkg }
141138
}
142139

143-
// OK
144140
async createIssueAlerts({
145141
pkg,
146142
alerts,
@@ -212,7 +208,6 @@ export class Core {
212208
return alerts
213209
}
214210

215-
// OK
216211
compareIssueAlerts({
217212
newScanAlerts,
218213
headScanAlerts,
@@ -260,7 +255,6 @@ export class Core {
260255
return alerts
261256
}
262257

263-
// OK
264258
checkAlertCapabilities({
265259
pkg,
266260
capabilities,
@@ -299,7 +293,6 @@ export class Core {
299293
return capabilities
300294
}
301295

302-
// OK
303296
compareCapabilities({
304297
newPackages,
305298
headPackages
@@ -336,7 +329,6 @@ export class Core {
336329
return capabilities
337330
}
338331

339-
// OK
340332
addCapabilitiesToPurl(diff: Diff): Diff {
341333
const newPackages: Purl[] = []
342334

@@ -463,7 +455,6 @@ export class Core {
463455
return pkg
464456
}
465457

466-
// OK
467458
createSbomDict(
468459
sbomArtifacts: Awaited<ReturnType<typeof this.getSbomData>>
469460
): Record<string, Package> {

src/commands/action/core/messages.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/messages.py
12
import { Diff, Issue, Purl } from './classes'
23

34
export class Messages {
4-
// OK
5-
createSecurityCommentJSON({ diff }: { diff: Diff }) {
5+
static createSecurityCommentJSON({ diff }: { diff: Diff }) {
66
let scanFailed = false
77

88
if (diff.newAlerts.length === 0) {
9-
// TODO: unreachable code
9+
// FIXME: unreachable code
1010
for (const alert of diff.newAlerts) {
1111
if (alert.error) {
1212
scanFailed = true
@@ -31,13 +31,11 @@ export class Messages {
3131
return output
3232
}
3333

34-
// OK
3534
static createPurlLink(purl: Purl): string {
3635
const packageUrl = `[${purl.purl}](${purl.url})`
3736
return packageUrl
3837
}
3938

40-
// OK
4139
static createAddedTable(diff: Diff): string {
4240
const overviewTable = [
4341
'Package',
@@ -72,7 +70,6 @@ export class Messages {
7270
return md
7371
}
7472

75-
// OK
7673
static createRemoveLine(diff: Diff): string {
7774
const removedLine = ['Removed packages:']
7875
for (const removed of diff.removedPackages) {
@@ -82,7 +79,6 @@ export class Messages {
8279
return removedLine.join(', ')
8380
}
8481

85-
// OK
8682
static dependencyOverviewTemplate(diff: Diff): string {
8783
let md = ''
8884
md += '<!-- socket-overview-comment-actions -->\n'
@@ -96,7 +92,6 @@ export class Messages {
9692
return md
9793
}
9894

99-
// OK
10095
static createSources(alert: Issue): [string, string] {
10196
const sources: string[] = []
10297
const manifests: string[] = []
@@ -117,7 +112,6 @@ export class Messages {
117112
return [manifestStr, sourcesStr]
118113
}
119114

120-
// OK
121115
static createSecurityAlertTable(diff: Diff): {
122116
ignoreCommands: string[]
123117
nextSteps: Record<string, string[]>
@@ -165,7 +159,6 @@ export class Messages {
165159
return { ignoreCommands, nextSteps, mdTable: md }
166160
}
167161

168-
// OK
169162
static createNextSteps(nextSteps: Record<string, string[]>): string {
170163
let md = ''
171164
for (const step in nextSteps) {
@@ -180,7 +173,6 @@ export class Messages {
180173
return md
181174
}
182175

183-
// OK
184176
static createDeeperLook(): string {
185177
let md = ''
186178
md += '<details>\n'
@@ -191,7 +183,6 @@ export class Messages {
191183
return md
192184
}
193185

194-
// OK
195186
static createRemovePackage(): string {
196187
let md = ''
197188
md += '<details>\n'
@@ -202,7 +193,6 @@ export class Messages {
202193
return md
203194
}
204195

205-
// OK
206196
static createAcceptableRisk(ignoreCommands: string[]): string {
207197
let md = ''
208198
md += '<details>\n'
@@ -218,7 +208,6 @@ export class Messages {
218208
return md
219209
}
220210

221-
// OK
222211
static securityCommentTemplate(diff: Diff): string {
223212
let md = ''
224213
md += '<!-- socket-security-comment-actions -->\n'

src/commands/action/core/scm_comments.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/core/scm_comments.py
12
import { Comment, Issue } from './classes'
23

34
export type SocketComments = {

src/commands/action/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
// https://github.com/SocketDev/socket-python-cli/blob/6d4fc56faee68d3a4764f1f80f84710635bdaf05/socketsecurity/socketcli.py
12
import { parseArgs } from 'util'
23
import { CliSubcommand } from '../../utils/meow-with-subcommands'
34
import simpleGit from 'simple-git'
45
import { SocketSdk } from '@socketsecurity/sdk'
56
import micromatch from 'micromatch'
6-
import { getDefaultKey } from '../../utils/sdk'
7+
import { getDefaultToken } from '../../utils/sdk'
78
import { Core } from './core'
89
import { GitHub } from './core/github'
910
import { SCMComments } from './core/scm_comments'
1011
import { Messages } from './core/messages'
1112

12-
const socket = new SocketSdk(getDefaultKey()!)
13+
const socket = new SocketSdk(getDefaultToken()!)
1314

1415
export const action: CliSubcommand = {
1516
description: 'Socket action command',
@@ -71,11 +72,8 @@ export const action: CliSubcommand = {
7172
const securityComment = Messages.securityCommentTemplate(diff)
7273
let newSecurityComment = true
7374
let newOverviewComment = true
74-
// TODO: overviewComment is never undefined or empty string
75-
let updateOldSecurityComment =
76-
securityComment === '' || comments.security !== undefined
77-
let updateOldOverviewComment =
78-
overviewComment === '' || comments.overview !== undefined
75+
let updateOldSecurityComment = comments.security !== undefined
76+
let updateOldOverviewComment = comments.overview !== undefined
7977
if (diff.newAlerts.length === 0) {
8078
if (!updateOldSecurityComment) {
8179
newSecurityComment = false

0 commit comments

Comments
 (0)