-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IssueContext handler to provide more context when issues are open…
…ed (#290) Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
- Loading branch information
Showing
6 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"integration: demo": >- | ||
This is a demo integration. | ||
"integration: zha": >- | ||
Please make sure your report includes the following things: | ||
|
||
1. Please enable ZHA debug logging, let it run for 10-15 minutes, and make sure to capture whatever problem you're having in the debug log. | ||
2. Download diagnostics JSON for the ZHA Integration for the specific devices you're having problems with. | ||
3. Any issues whatsoever with Tuya devices or device support requests in general need to be made in the ZHA quirks repo https://github.com/zigpy/zha-device-handlers/issues, not Core's issue tracker. | ||
5. Fill out the issue template and include whether or not you're using a VM/Proxmox with USB passthrough, what addons you have installed, and so on. | ||
|
||
ZHA does not have low-level control over your network, the mesh is self-organizing. If you started having network issues in a specific release, the release probably didn't cause the issue. Check your environment for new sources of 2.4GHz interference and make sure you're using an extension cable, not placing the coordinator near SSDs and USB 3.0 ports, etc. Just because things worked in the past with a bad setup doesn't mean they'll keep working in the future. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
services/bots/src/github-webhook/handlers/issue_context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { IssuesLabeledEvent } from '@octokit/webhooks-types'; | ||
import findUp from 'find-up'; | ||
import { readFileSync } from 'fs'; | ||
import yaml from 'js-yaml'; | ||
import { join } from 'path'; | ||
import { EventType, HomeAssistantRepository } from '../github-webhook.const'; | ||
import { WebhookContext } from '../github-webhook.model'; | ||
import { BaseWebhookHandler } from './base'; | ||
|
||
const dataDirectory = findUp.sync('data', { cwd: __filename, type: 'directory' }); | ||
const issueContext = yaml.load( | ||
readFileSync(join(dataDirectory, 'github', 'issue_context.yaml')).toString(), | ||
{ | ||
json: true, | ||
}, | ||
) as Record<string, string>; | ||
const withIssueContext = Object.keys(issueContext); | ||
|
||
export class IssueContext extends BaseWebhookHandler { | ||
public allowedEventTypes = [EventType.ISSUES_LABELED]; | ||
public allowedRepositories = [HomeAssistantRepository.CORE]; | ||
|
||
async handle(context: WebhookContext<IssuesLabeledEvent>) { | ||
if (!context.payload.label || !withIssueContext.includes(context.payload.label.name)) { | ||
return; | ||
} | ||
context.scheduleIssueComment({ | ||
handler: 'IssueContext', | ||
comment: issueContext[context.payload.label.name], | ||
}); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
tests/services/bots/github-webhook/handlers/issue_context.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @ts-nocheck | ||
import * as assert from 'assert'; | ||
import { WebhookContext } from '../../../../../bots/src/github-webhook/github-webhook.model'; | ||
import { IssueContext } from '../../../../../services/bots/src/github-webhook/handlers/issue_context'; | ||
import { mockWebhookContext } from '../../../../utils/test_context'; | ||
import { loadJsonFixture } from '../../../../utils/fixture'; | ||
|
||
describe('IssueContext', () => { | ||
let handler: IssueContext; | ||
let mockContext: WebhookContext<any>; | ||
let getLabelResponse: any; | ||
|
||
beforeEach(function () { | ||
handler = new IssueContext(); | ||
getLabelResponse = {}; | ||
mockContext = mockWebhookContext({ | ||
eventType: 'issues.labeled', | ||
payload: loadJsonFixture('pull_request.opened', { | ||
label: { name: 'integration: demo' }, | ||
}), | ||
github: { | ||
issues: { | ||
async getLabel() { | ||
return getLabelResponse; | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('Add comment', async () => { | ||
await handler.handle(mockContext); | ||
|
||
assert.deepStrictEqual(mockContext.scheduledComments, [ | ||
{ | ||
handler: 'IssueContext', | ||
comment: 'This is a demo integration.', | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters