Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into dependabot/github_actions/github/super-linte…
Browse files Browse the repository at this point in the history
…r-v3.16.1
  • Loading branch information
zkoppert authored Apr 28, 2021
2 parents 93b9147 + 92bb92d commit 0321bbb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
21 changes: 18 additions & 3 deletions lib/RallyValidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,17 @@ class RallyValidate {
* @returns {Promise<void>}
*/
async handlePullRequest (context) {
await this.handlePullRequestWithRally (context, this.initializeRallyClient)
}

/**
* Process the pull request with the given initializeRallyClient
*
* @param context
* @param _initializeRallyClient
* @returns {Promise<void>}
*/
async handlePullRequestWithRally(context, _initializeRallyClient) {
// Initialize Rally Artifacts
const rallyArtifacts = {}

Expand All @@ -155,7 +166,7 @@ class RallyValidate {
await this.setStatusPending(context, config)

try {
const rallyClient = await this.initializeRallyClient(config)
const rallyClient = await _initializeRallyClient(config)
// Get commit comments for validation
rallyArtifacts.commits = await this.checkCommitMessages(context, config, rallyClient)
// Get the PR title for validation
Expand Down Expand Up @@ -408,8 +419,12 @@ class RallyValidate {
* @returns {Promise<void>}
*/
async commentOnPull (context, message) {
const params = context.artifact({ body: message })
await context.github.artifacts.createComment(params)
await context.github.issues.createComment({
owner: context.payload.repository.owner.login,
repo: context.payload.repository.name,
issue_number: context.payload.pull_request.number,
body: message
})
}

/**
Expand Down
28 changes: 26 additions & 2 deletions test/RallyValidate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('JiraIssueValidate', () => {
commits: [
{
commit: {
message: 'hello!'
message: 'fix: US1234 hello!'
},
sha: '1234lkajsdfkjsdf'
}
Expand All @@ -47,6 +47,9 @@ describe('JiraIssueValidate', () => {
content: probotConfigEncodedYaml
}
}))
},
issues: {
createComment: jest.fn().mockImplementation(() => Promise.resolve({}))
}
},
repo: jest.fn().mockImplementation((input) => { return input }),
Expand All @@ -61,12 +64,33 @@ describe('JiraIssueValidate', () => {
TotalResultCount: 1,
Results: [
{
_ref: 'https://rallydomain.com/my-ref'
_ref: 'https://rallydomain.com/my-ref',
Project: {
_refObjectName: 'Sample Project'
},
ScheduleState: 'Defined'
}
]
})),
update: jest.fn()
}
initializeRallyClient = jest.fn().mockImplementation(() => Promise.resolve(rallyClient)) // eslint-disable-line
})

describe('hook', () => {
it('pull_request.synchronize', async () => {
await handler.handlePullRequestWithRally(context, initializeRallyClient) // eslint-disable-line
expect(context.config).toHaveBeenCalled()
expect(context.github.checks.create.mock.calls).toEqual([
[context.repo(expect.objectContaining({
status: 'in_progress'
}))],
[context.repo(expect.objectContaining({
conclusion: 'success',
status: 'completed'
}))]
])
})
})

describe('get configuration', () => {
Expand Down

0 comments on commit 0321bbb

Please sign in to comment.