예제 #1
0
        /// <summary>
        /// Issue作成
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public async Task CreateIssue(SlackRequest.Active <IssueData> data)
        {
            // =============================
            // Issueオブジェクト作成
            // =============================
            var newIssue = new NewIssue(data.Submission.Title)
            {
                Body = data.Submission.Body
            };

            newIssue.Labels.Add(data.Submission.Label);

            // =============================
            // GitHubアクセストークンの設定
            // =============================
            GitHubApi.SetCredential(data.User.Id);

            // =============================
            // 登録リポジトリ取得
            // =============================
            await GetRepository(data.Channel.Id, data.Response_url, data.Team.Id, async repository =>
            {
                // GitHub認証エラーハンドリング
                await AuthorizationExceptionHandler(data.Channel.Id, data.Response_url, data.Team.Id, async() =>
                {
                    // =============================
                    // Issue作成
                    // =============================
                    var issue = await GitHubApi.Client.Issue.Create(repository.Split('/')[0], repository.Split('/')[1], newIssue);

                    var model = new PostMessageModel()
                    {
                        Channel       = data.Channel.Id,
                        Text          = "Issueが登録されました" + Environment.NewLine + "https://github.com/" + repository + "/issues/" + issue.Number,
                        Response_type = "in_channel",
                        Unfurl_links  = true
                    };

                    await SlackApi.ExecutePostApiAsJson(model, data.Response_url, data.Team.Id);
                });
            });
        }
예제 #2
0
        public async Task Create(HttpRequestMessage request)
        {
            // ===========================
            // リクエストの取得・整形
            // ===========================
            var data = await GetBody(request);

            // 引数の値
            var method = data["text"];


            // ===========================
            // 引数の値で処理を分ける
            // ===========================
            switch (method)
            {
            // ===========================
            // issue登録
            // ===========================
            case "create":
            {
                // =============================
                // GitHubアクセストークンの設定
                // =============================
                GitHubApi.SetCredential(data["user_id"]);

                // =============================
                // 登録リポジトリ照会
                // =============================

                await GetRepository(data["channel_id"], data["response_url"], data["team_id"], async repository =>
                    {
                        List <string> labelNameList = null;

                        // GitHub認証エラーハンドリング
                        await AuthorizationExceptionHandler(data["channel_id"], data["response_url"], data["team_id"],
                                                            async() =>
                        {
                            // クライアントを用いてリポジトリ名からIssueのラベルを取得
                            var labelList =
                                await GitHubApi.Client.Issue.Labels.GetAllForRepository(repository.Split('/')[0],
                                                                                        repository.Split('/')[1]);

                            // ラベル変数リストを文字列リストに変換
                            labelNameList = labelList.ToList().ConvertAll(x => x.Name);
                        });

                        // ===============================
                        // Issue作成用ダイアログモデル作成
                        // ===============================
                        var model = CreateDialogModelForCreateIssue(data["trigger_id"], labelNameList);

                        // =============================
                        // ダイアログAPI実行
                        // =============================
                        await SlackApi.ExecutePostApiAsJson(model, "https://slack.com/api/dialog.open",
                                                            data["team_id"]);
                    });

                break;
            }

            case "export":
            {
                List <Issue> issueList = null;

                // =============================
                // 登録リポジトリ照会
                // =============================
                await GetRepository(data["channel_id"], data["response_url"], data["team_id"], async repository =>
                    {
                        // GitHub認証エラーハンドリング
                        await AuthorizationExceptionHandler(data["channel_id"], data["response_url"], data["team_id"],
                                                            async() =>
                        {
                            var issueROList = await GitHubApi.Client.Issue.GetAllForRepository(
                                repository.Split('/')[0],
                                repository.Split('/')[1]);
                            issueList = issueROList.ToList();
                        });
                    });

                var issueText = string.Empty;
                foreach (var issue in issueList)
                {
                    var assigneesString = issue.Assignees.Any() ? string.Join(" ", issue.Assignees.Select(x => x.Login)) : "";

                    issueText +=
                        $"```\n***issueID***\n{issue.Number}\n***アサイン者***\n{assigneesString}\n***タイトル***\n{issue.Title}\n***本文***\n{issue.Body}\n***登録者?***{issue.User.Login}\n***状態***\n{issue.State.StringValue}\n```";
                }

                var model = new PostMessageModel()
                {
                    Channel       = data["channel_id"],
                    Text          = issueText,
                    Response_type = "ephemeral"
                };

                await SlackApi.ExecutePostApiAsJson(model, data["response_url"], data["team_id"]);

                break;
            }

            // ===========================
            // それ以外
            // ===========================
            default:
            {
                var model = new PostMessageModel()
                {
                    Channel       = data["channel_id"],
                    Text          = "引数を入力してください",
                    Response_type = "ephemeral"
                };

                await SlackApi.ExecutePostApiAsJson(model, data["response_url"], data["team_id"]);

                break;
            }
            }

            #endregion
        }