grigori-gru/jira-to-matrix

View on GitHub
src/messengers/matrix-api.ts

Summary

Maintainability
F
6 days
Test Coverage

File matrix-api.ts has 787 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/* eslint-disable no-undefined */
/* eslint no-empty-function: ["error", { "allow": ["arrowFunctions"] }] */
import matrixSdk from 'matrix-js-sdk';
import { errorTracing } from '../lib/utils';
import * as R from 'ramda';
Severity: Major
Found in src/messengers/matrix-api.ts - About 1 day to fix

    MatrixApi has 63 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class MatrixApi extends BaseChatApi implements MessengerApi {
        userId: string;
        baseUrl: string;
        // matrix client
        client: any;
    Severity: Major
    Found in src/messengers/matrix-api.ts - About 1 day to fix

      Function timelineHandler has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async timelineHandler(event: any, room: any, toStartOfTimeline: boolean) {
              try {
                  if (event.getType() !== 'm.room.message' || toStartOfTimeline) {
                      return;
                  }
      Severity: Minor
      Found in src/messengers/matrix-api.ts - About 1 hr to fix

        Function parseTextBody has 40 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            parseTextBody(body: string): SuccessParse | FailParse {
                try {
                    const trimedBody = body.trim();
        
                    const commandNameFromUser = R.pipe(
        Severity: Minor
        Found in src/messengers/matrix-api.ts - About 1 hr to fix

          Function upload has 27 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async upload(roomId: string, url: string): Promise<string | undefined> {
                  try {
                      const mimeTypes = [
                          'image/apng',
                          'image/bmp',
          Severity: Minor
          Found in src/messengers/matrix-api.ts - About 1 hr to fix

            Function timelineHandler has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                async timelineHandler(event: any, room: any, toStartOfTimeline: boolean) {
                    try {
                        if (event.getType() !== 'm.room.message' || toStartOfTimeline) {
                            return;
                        }
            Severity: Minor
            Found in src/messengers/matrix-api.ts - About 55 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Avoid too many return statements within this function.
            Open

                        return {
                            isSuccess: false,
                        };
            Severity: Major
            Found in src/messengers/matrix-api.ts - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return;
              Severity: Major
              Found in src/messengers/matrix-api.ts - About 30 mins to fix

                Function parseTextBody has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    parseTextBody(body: string): SuccessParse | FailParse {
                        try {
                            const trimedBody = body.trim();
                
                            const commandNameFromUser = R.pipe(
                Severity: Minor
                Found in src/messengers/matrix-api.ts - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    parseFileBody(content: FileContent): SuccessParse | FailParse {
                        if (!this.config.features.postEachComments) {
                            return {
                                isSuccess: false,
                            };
                Severity: Major
                Found in src/messengers/matrix-api.ts and 1 other location - About 5 hrs to fix
                src/messengers/matrix-api.ts on lines 219..240

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 147.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    parseImageBody(content: ImageContent): SuccessParse | FailParse {
                        if (!this.config.features.postEachComments) {
                            return {
                                isSuccess: false,
                            };
                Severity: Major
                Found in src/messengers/matrix-api.ts and 1 other location - About 5 hrs to fix
                src/messengers/matrix-api.ts on lines 196..217

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 147.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                        try {
                            await this.client.sendTextMessage(roomId, body);
                        } catch (err) {
                            if (this._isEventExeptionError(err)) {
                                this.logger.warn(err.message);
                Severity: Major
                Found in src/messengers/matrix-api.ts and 1 other location - About 1 hr to fix
                src/messengers/matrix-api.ts on lines 719..729

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 57.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                        try {
                            await this.client.sendHtmlMessage(roomId, body, htmlBody);
                        } catch (err) {
                            if (this._isEventExeptionError(err)) {
                                this.logger.warn(err.message);
                Severity: Major
                Found in src/messengers/matrix-api.ts and 1 other location - About 1 hr to fix
                src/messengers/matrix-api.ts on lines 702..712

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 57.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 4 locations. Consider refactoring.
                Open

                    async getRoomMembers({
                        name,
                        roomId,
                    }: { name: string; roomId?: string } | { name?: string; roomId: string }): Promise<string[]> {
                        try {
                Severity: Major
                Found in src/messengers/matrix-api.ts and 3 other locations - About 45 mins to fix
                src/messengers/matrix-api.ts on lines 648..665
                src/messengers/matrix-api.ts on lines 974..992
                src/messengers/slack-api.ts on lines 341..350

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 50.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 4 locations. Consider refactoring.
                Open

                    async getRoomAdmins({
                        name,
                        roomId,
                    }: { name?: string; roomId: string } | { name: string; roomId?: string }): Promise<
                        { name: string; userId: string }[]
                Severity: Major
                Found in src/messengers/matrix-api.ts and 3 other locations - About 45 mins to fix
                src/messengers/matrix-api.ts on lines 630..643
                src/messengers/matrix-api.ts on lines 974..992
                src/messengers/slack-api.ts on lines 341..350

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 50.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 4 locations. Consider refactoring.
                Open

                    async joinRoom({
                        roomId,
                        aliasPart,
                    }: { roomId?: string; aliasPart: string } | { roomId: string; aliasPart?: string }) {
                        try {
                Severity: Major
                Found in src/messengers/matrix-api.ts and 3 other locations - About 45 mins to fix
                src/messengers/matrix-api.ts on lines 630..643
                src/messengers/matrix-api.ts on lines 648..665
                src/messengers/slack-api.ts on lines 341..350

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 50.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        try {
                            const method = 'GET';
                            const path = `/rooms/${encodeURIComponent(roomId)}/messages`;
                            const qweryParams = { limit, dir: 'b' };
                            const body = {};
                Severity: Minor
                Found in src/messengers/matrix-api.ts and 2 other locations - About 35 mins to fix
                src/messengers/matrix-api.ts on lines 843..864
                src/messengers/matrix-api.ts on lines 946..958

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 47.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        try {
                            const method = 'PUT';
                            const path = `/rooms/${encodeURIComponent(roomId)}/state/m.room.join_rules`;
                            // eslint-disable-next-line @typescript-eslint/camelcase
                            const body = { join_rule: 'public' };
                Severity: Minor
                Found in src/messengers/matrix-api.ts and 2 other locations - About 35 mins to fix
                src/messengers/matrix-api.ts on lines 843..864
                src/messengers/matrix-api.ts on lines 909..921

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 47.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 3 locations. Consider refactoring.
                Open

                        try {
                            const method = 'GET';
                            const path = `/rooms/${encodeURIComponent(roomId)}/messages`;
                            const qweryParams = { limit: 10000, dir: 'b' };
                            const body = {};
                Severity: Minor
                Found in src/messengers/matrix-api.ts and 2 other locations - About 35 mins to fix
                src/messengers/matrix-api.ts on lines 909..921
                src/messengers/matrix-api.ts on lines 946..958

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 47.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status