Skip to content
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
7 changes: 3 additions & 4 deletions backend/src/database/repositories/memberRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,6 @@ class MemberRepository {
attributesSettings = [] as AttributeData[],
segments: string[] = [],
): Promise<PageData<IActiveMemberData>> {

const tenant = SequelizeRepository.getCurrentTenant(options)

const segmentsEnabled = await isFeatureEnabled(FeatureFlag.SEGMENTS, options)
Expand Down Expand Up @@ -1108,9 +1107,9 @@ class MemberRepository {
},
{
term: {
uuid_tenantId: tenant.id
}
}
uuid_tenantId: tenant.id,
},
},
],
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ import PullRequestReviewThreadCommentsQuery from '../../usecases/github/graphql/
import PullRequestCommitsQuery, {
PullRequestCommit,
} from '../../usecases/github/graphql/pullRequestCommits'
import PullRequestCommitsQueryNoAdditions, {
PullRequestCommitNoAdditions,
} from '../../usecases/github/graphql/pullRequestCommitsNoAdditions'
import IntegrationRunRepository from '../../../../database/repositories/integrationRunRepository'
import { IntegrationRunState } from '../../../../types/integrationRunTypes'
import IntegrationStreamRepository from '../../../../database/repositories/integrationStreamRepository'
Expand Down Expand Up @@ -302,7 +305,24 @@ export class GithubIntegrationService extends IntegrationServiceBase {
context.integration.token,
)

result = await pullRequestCommitsQuery.getSinglePage(stream.metadata.page)
try {
result = await pullRequestCommitsQuery.getSinglePage(stream.metadata.page)
} catch (err) {
context.logger.warn(
{
err,
repo,
pullRequestNumber,
},
'Error while fetching pull request commits. Trying again without additions.',
)
const pullRequestCommitsQueryNoAdditions = new PullRequestCommitsQueryNoAdditions(
repo,
pullRequestNumber,
context.integration.token,
)
result = await pullRequestCommitsQueryNoAdditions.getSinglePage(stream.metadata.page)
}
break
case GithubStreamType.ISSUES:
const issuesQuery = new IssuesQuery(repo, context.integration.token)
Expand Down Expand Up @@ -1317,7 +1337,7 @@ export class GithubIntegrationService extends IntegrationServiceBase {
context: IStepContext,
): Promise<AddActivitiesSingle[]> {
const out: AddActivitiesSingle[] = []
const data = records[0] as PullRequestCommit
const data = records[0] as PullRequestCommit | PullRequestCommitNoAdditions
const commits = data.repository.pullRequest.commits.nodes

for (const record of commits) {
Expand All @@ -1339,9 +1359,10 @@ export class GithubIntegrationService extends IntegrationServiceBase {
sourceParentId: `${data.repository.pullRequest.id}`,
timestamp: moment(record.commit.authoredDate).utc().toDate(),
attributes: {
insertions: record.commit.additions,
deletions: record.commit.deletions,
lines: record.commit.additions - record.commit.deletions,
insertions: 'additions' in record.commit ? record.commit.additions : 0,
deletions: 'additions' in record.commit ? record.commit.deletions : 0,
lines:
'additions' in record.commit ? record.commit.additions - record.commit.deletions : 0,
isMerge: record.commit.parents.totalCount > 1,
isMainBranch: false,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Repo } from '../../../types/regularTypes'
import BaseQuery from './baseQuery'

export interface PullRequestCommitNoAdditions {
repository: {
pullRequest: {
id: string
number: number
baseRefName: string
headRefName: string
commits: {
pageInfo: {
hasPreviousPage: boolean
startCursor: string
}
nodes: {
commit: {
authoredDate: string
committedDate: string
changedFiles: number
deletions: number
oid: string
message: string
url: string
parents: {
totalCount: number
}
authors: {
nodes: {
user: {
login: string
name: string
avatarUrl: string
id: string
isHireable: boolean
twitterUsername: string | null
url: string
websiteUrl: string | null
email: string
bio: string
company: string
location: string | null
followers: {
totalCount: number
}
}
}[]
}
}
}[]
}
}
}
}

/* eslint class-methods-use-this: 0 */
class PullRequestCommitsQueryNoAdditions extends BaseQuery {
repo: Repo

constructor(
repo: Repo,
pullRequestNumber: string,
githubToken: string,
perPage: number = 100,
maxAuthors: number = 1,
) {
const pullRequestCommitsQuery = `{
repository(name: "${repo.name}", owner: "${repo.owner}") {
pullRequest(number: ${pullRequestNumber}) {
id
number
baseRefName
headRefName
commits(first: ${perPage}, \${beforeCursor}) {
pageInfo ${BaseQuery.PAGE_SELECT}
nodes {
commit {
authoredDate
committedDate
changedFiles
deletions
oid
message
url
parents(first: 2) {
totalCount
}
authors(first: ${maxAuthors}) {
nodes {
user ${BaseQuery.USER_SELECT}
}
}
}
}
}
}
}
}`

super(githubToken, pullRequestCommitsQuery, 'pullRequestCommits', perPage)

this.repo = repo
}

// Override the getEventData method to process commit details
getEventData(result) {
const commitData = result as PullRequestCommitNoAdditions

return {
hasPreviousPage: result.repository?.pullRequest?.commits?.pageInfo?.hasPreviousPage,
startCursor: result.repository?.pullRequest?.commits?.pageInfo?.startCursor,
data: [commitData], // returning an array to match the parseActivities function
}
}
}

export default PullRequestCommitsQueryNoAdditions