atomist-skills / auto-link-channel-skill

Atomist Skill to map repositories to chat channels and invite committers
Apache License 2.0
0 stars 0 forks source link

MSTeams support #79

Closed slimslenderslacks closed 4 years ago

slimslenderslacks commented 4 years ago

When we create a new repo on a team with MSTeams, the skill successfully creates the channel but can not link it. It could be that the skill only supports Slack teams today.

09:44:57.953 
ERROR: Error occurred: Error: [
  {
    "message": "Failed to join slack channel: Team not found with id 19:1cbbd0651ae34f84a634dde276b69f63@thread.tacv2",
    "code": 404
  }
]
    at NodeFetchGraphQLClient.mutate (/workspace/bundle/index.js:134062:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at module.exports.269.exports.handler (/workspace/bundle/index.js:23531:9)
    at Object.processEvent (/workspace/bundle/index.js:189590:25)
09:44:57.954 
TRACE:   }
09:44:57.954 
TRACE:     "code": 404
09:44:57.954 
TRACE:     at processTicksAndRejections (internal/process/task_queues.js:97:5)
09:44:57.954 
TRACE:     at module.exports.269.exports.handler (/workspace/bundle/index.js:23531:9)
09:44:57.954 
TRACE:   {
09:44:57.954 
TRACE:     at Object.processEvent (/workspace/bundle/index.js:189590:25)
09:44:57.954 
TRACE:     "message": "Failed to join slack channel: Team not found with id 19:1cbbd0651ae34f84a634dde276b69f63@thread.tacv2",
09:44:57.954 
TRACE:     at NodeFetchGraphQLClient.mutate (/workspace/bundle/index.js:134062:19)
09:44:57.954 
TRACE: ]
09:44:57.954 
TRACE: [error] Error occurred: Error: [
09:44:58.370 
TRACE: [debug] Sending message: {"api_version":"1","correlation_id":"42bd4b78-cf7c-4c8e-ab1c-886159dcc9cc.1asiP7dQF03QtVHYSIwG8","team":{"id":"A3P0OHOOZ","name":"msteams"},"event":"PushToUnmappedRepo","status":{"code":1,"reason":"Error invoking atomist/auto-link-channel-skill"},"skill":{"id":"78a7cd1c-57ef-4da2-a5be-50de771755c2","name":"auto-link-channel-skill","version":"0.1.5","platform":"gcf","artifacts":[{"url":"g***********************************************************************************************************************************p","name":"gcf","memory":512,"runtime":"nodejs12","timeout":60,"__typename":"AtomistSkillGCFArtifact","entryPoint":"entryPoint"}],"namespace":"atomist","configuration":{"repository":{"commitSha":"c93864452e6cb9a7fb1305e9071b3670847fdf45"},"instances":[{"name":"auto-link_chat_channels","signals":null,"parameters":[{"name":"invite","value":false},{"name":"ignore","value":[]},{"name":"repos","value":{"excludes":null,"includes":null}}],"displayName":"Auto-Link Chat Channels","resourceProviders":[{"name":"github","typeName":"GitHubAppResourceProvider","selectedResourceProviders":[{"id":"A3P0OHOOZ_4213884e-29a1-4e1b-a01f-356af2656b7d"}]},{"name":"chat","typeName":"ChatProvider","selectedResourceProviders":[{"id":"4b1c0af7-a444-490d-8ca9-346c7d7d6d7e"}]}]}]},"dispatchStyle":"multiple"}}
09:44:58.408 
TRACE: [debug] Completed event handler 'PushToUnmappedRepo'
09:44:58.467 
DEBUG: Function execution took 4222 ms, finished with status: 'ok'
cdupuis commented 4 years ago

@slimslenderslacks This skill uses the repo.org.chatTeam.id field to pass into the various mutations as teamId.

Here's the payload of the relevant skill invocation:

{
    "data": {
        "Push": [
            {
                "commits": [
                    {
                        "committer": {
                            "login": "slimslenderslacks",
                            "person": {
                                "chatId": {
                                    "screenName": "Jim Clark",
                                    "userId": "2****************************************************************************************Q"
                                }
                            }
                        }
                    }
                ],
                "repo": {
                    "channels": [],
                    "name": "blah",
                    "org": {
                        "chatTeam": {
                            "id": "19:1cbbd0651ae34f84a634dde276b69f63@thread.tacv2"
                        },
                        "provider": {
                            "providerId": "4213884e-29a1-4e1b-a01f-356af2656b7d"
                        }
                    },
                    "owner": "slimslender",
                    "url": "h*********************************h"
                }
            }
        ]
    },
    "extensions": {
        "operationName": "PushToUnmappedRepo",
        "query_id": "cc7233a1-8d15-41ed-96ec-c17cb6dde395",
        "team_id": "A3P0OHOOZ",
        "team_name": "msteams",
        "correlation_id": "42bd4b78-cf7c-4c8e-ab1c-886159dcc9cc.1asiP7dQF03QtVHYSIwG8",
        "log_url": "h*********************************************************************************************8"
    },
    "secrets": [
        {
            "uri": "atomist://api-key",
            "value": "e********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************g"
        }
    ],
    "skill": {
        "id": "78a7cd1c-57ef-4da2-a5be-50de771755c2",
        "name": "auto-link-channel-skill",
        "version": "0.1.5",
        "platform": "gcf",
        "artifacts": [
            {
                "url": "g***********************************************************************************************************************************p",
                "name": "gcf",
                "memory": 512,
                "runtime": "nodejs12",
                "timeout": 60,
                "__typename": "AtomistSkillGCFArtifact",
                "entryPoint": "entryPoint"
            }
        ],
        "namespace": "atomist",
        "configuration": {
            "repository": {
                "commitSha": "c93864452e6cb9a7fb1305e9071b3670847fdf45"
            },
            "instances": [
                {
                    "name": "auto-link_chat_channels",
                    "signals": null,
                    "parameters": [
                        {
                            "name": "invite",
                            "value": false
                        },
                        {
                            "name": "ignore",
                            "value": []
                        },
                        {
                            "name": "repos",
                            "value": {
                                "excludes": null,
                                "includes": null
                            }
                        }
                    ],
                    "displayName": "Auto-Link Chat Channels",
                    "resourceProviders": [
                        {
                            "name": "github",
                            "typeName": "GitHubAppResourceProvider",
                            "selectedResourceProviders": [
                                {
                                    "id": "A3P0OHOOZ_4213884e-29a1-4e1b-a01f-356af2656b7d"
                                }
                            ]
                        },
                        {
                            "name": "chat",
                            "typeName": "ChatProvider",
                            "selectedResourceProviders": [
                                {
                                    "id": "4b1c0af7-a444-490d-8ca9-346c7d7d6d7e"
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        "dispatchStyle": "multiple"
    }
}

As you can see repo.org.chatTeam.id is 19:1cbbd0651ae34f84a634dde276b69f63@thread.tacv2 which apparently is not a correct chatTeam id per the error message.

Here's the mutation call that fails:

{"query":"mutation addBotToChannel($teamId: String!, $channelId: String!) {  addBotToSlackChannel(chatTeamId: $teamId, channelId: $channelId) {    id  }}","variables":{"teamId":"19:1cbbd0651ae34f84a634dde276b69f63@thread.tacv2","channelId":"19:6e32a7987f70425bb1886236b96b79de@thread.tacv2"}}

Also the same chatTeamId worked fine in a previous mutation call:

{"query":"mutation createChannel($teamId: String!, $name: String!) { createSlackChannel(chatTeamId: $teamId, name: $name) { id }}","variables":{"teamId":"19:1cbbd0651ae34f84a634dde276b69f63@thread.tacv2","name":"blah"}}

I don't think this is a skill issue and I'm inclined to close this here.

slimslenderslacks commented 4 years ago

@dansmithy maybe you can help with requirements on this. I think addBotToChannel is either not meant to be called for MSTeams (because the bot is always in the channel), or the mutation itself should no-op when MSTeams is called.

I think we got actually created the channel correctly but the skill was marked as having failed because of the above. I'm not sure. If we decide that addBotToChannel should not fail for MSTeams then we should close this issue and open another one. But at the moment, the skill looks like it fails for MSTeams.

slimslenderslacks commented 4 years ago

As far as I can tell, the channel linking for MSTeams was actually working - it's just that it looked like it wasn't working because of the failure and because the github notifications skill had to be deleted and re-enabled on this team.

cdupuis commented 4 years ago

Yeah, it certainly failed because the mutation failure and also did not invite committers to the newly created channel.

cdupuis commented 4 years ago

@slimslenderslacks I've put a hack in that checks if the team is slack and only then calls the failing mutation. Using the unstable version of this skill should let you re-test this.

slimslenderslacks commented 4 years ago

Actually, one amendment to the above is that the channel was being created but not linked - I had to link it manually. But let me flip this over to unstable, and see if it gets linked.

cdupuis commented 4 years ago

Actually, one amendment to the above is that the channel was being created but not linked - I had to link it manually. But let me flip this over to unstable, and see if it gets linked.

Yes, I know it didn't link because linking comes after inviting the bot.

slimslenderslacks commented 4 years ago

Moving on to version 0.1.6-6 is a big improvement in the flow. Channel is linked, and the skill completes successfully

slimslenderslacks commented 4 years ago

@cdupuis I've asked @dansmithy to talk to you about possibly having a mutation that no-ops for MS Teams.