| 
 | 1 | +import { axios } from "@pipedream/platform";  | 
 | 2 | + | 
1 | 3 | export default {  | 
2 | 4 |   type: "app",  | 
3 | 5 |   app: "circleci",  | 
4 |  | -  propDefinitions: {},  | 
 | 6 | +  version: "0.0.{{ts}}",  | 
 | 7 | +  propDefinitions: {  | 
 | 8 | +    // Required for creating a new item  | 
 | 9 | +    title: {  | 
 | 10 | +      type: "string",  | 
 | 11 | +      label: "Title",  | 
 | 12 | +      description: "The title of the item",  | 
 | 13 | +    },  | 
 | 14 | +    content: {  | 
 | 15 | +      type: "string",  | 
 | 16 | +      label: "Content",  | 
 | 17 | +      description: "The content of the item",  | 
 | 18 | +    },  | 
 | 19 | +    // Required for updating an existing item  | 
 | 20 | +    itemId: {  | 
 | 21 | +      type: "string",  | 
 | 22 | +      label: "Item ID",  | 
 | 23 | +      description: "The unique identifier of the item",  | 
 | 24 | +    },  | 
 | 25 | +    // Required for adding a comment  | 
 | 26 | +    commentContent: {  | 
 | 27 | +      type: "string",  | 
 | 28 | +      label: "Comment Content",  | 
 | 29 | +      description: "The content of the comment",  | 
 | 30 | +    },  | 
 | 31 | +    // Optional for creating a new item  | 
 | 32 | +    metadata: {  | 
 | 33 | +      type: "string",  | 
 | 34 | +      label: "Metadata",  | 
 | 35 | +      description: "Optional metadata as JSON string",  | 
 | 36 | +      optional: true,  | 
 | 37 | +    },  | 
 | 38 | +    // Optional for updating an existing item  | 
 | 39 | +    updateFields: {  | 
 | 40 | +      type: "string",  | 
 | 41 | +      label: "Fields to Update",  | 
 | 42 | +      description: "Fields to update in the item as JSON string",  | 
 | 43 | +      optional: true,  | 
 | 44 | +    },  | 
 | 45 | +    // Optional for adding a comment to an existing item  | 
 | 46 | +    userDetails: {  | 
 | 47 | +      type: "string",  | 
 | 48 | +      label: "User Details",  | 
 | 49 | +      description: "Optional user details as JSON string",  | 
 | 50 | +      optional: true,  | 
 | 51 | +    },  | 
 | 52 | +    // Optional filters for new item creation events  | 
 | 53 | +    newItemType: {  | 
 | 54 | +      type: "string",  | 
 | 55 | +      label: "Item Type",  | 
 | 56 | +      description: "Filter by item type",  | 
 | 57 | +      optional: true,  | 
 | 58 | +    },  | 
 | 59 | +    newItemStatus: {  | 
 | 60 | +      type: "string",  | 
 | 61 | +      label: "Status",  | 
 | 62 | +      description: "Filter by status",  | 
 | 63 | +      optional: true,  | 
 | 64 | +    },  | 
 | 65 | +    // Optional filters for item update events  | 
 | 66 | +    updatedItemFields: {  | 
 | 67 | +      type: "string",  | 
 | 68 | +      label: "Updated Fields",  | 
 | 69 | +      description: "Filter by updated fields",  | 
 | 70 | +      optional: true,  | 
 | 71 | +    },  | 
 | 72 | +    updatedItemType: {  | 
 | 73 | +      type: "string",  | 
 | 74 | +      label: "Item Type",  | 
 | 75 | +      description: "Filter by item type",  | 
 | 76 | +      optional: true,  | 
 | 77 | +    },  | 
 | 78 | +    // Optional filters for comment addition events  | 
 | 79 | +    commentItemType: {  | 
 | 80 | +      type: "string",  | 
 | 81 | +      label: "Item Type",  | 
 | 82 | +      description: "Filter by item type",  | 
 | 83 | +      optional: true,  | 
 | 84 | +    },  | 
 | 85 | +    commentUser: {  | 
 | 86 | +      type: "string",  | 
 | 87 | +      label: "User",  | 
 | 88 | +      description: "Filter by user",  | 
 | 89 | +      optional: true,  | 
 | 90 | +    },  | 
 | 91 | +  },  | 
5 | 92 |   methods: {  | 
6 |  | -    // this.$auth contains connected account data  | 
 | 93 | +    // This method logs the authentication keys  | 
7 | 94 |     authKeys() {  | 
8 | 95 |       console.log(Object.keys(this.$auth));  | 
9 | 96 |     },  | 
 | 97 | +    // Base URL for CircleCI API  | 
 | 98 | +    _baseUrl() {  | 
 | 99 | +      return "https://circleci.com/api/v2";  | 
 | 100 | +    },  | 
 | 101 | +    // Common method to make API requests  | 
 | 102 | +    async _makeRequest(opts = {}) {  | 
 | 103 | +      const {  | 
 | 104 | +        $ = this, method = "GET", path = "/", headers, ...otherOpts  | 
 | 105 | +      } = opts;  | 
 | 106 | +      return axios($, {  | 
 | 107 | +        method,  | 
 | 108 | +        url: this._baseUrl() + path,  | 
 | 109 | +        headers: {  | 
 | 110 | +          ...headers,  | 
 | 111 | +          Authorization: `Bearer ${this.$auth.api_key}`,  | 
 | 112 | +        },  | 
 | 113 | +        ...otherOpts,  | 
 | 114 | +      });  | 
 | 115 | +    },  | 
 | 116 | +    // Create a new item  | 
 | 117 | +    async createItem(opts = {}) {  | 
 | 118 | +      const {  | 
 | 119 | +        title, content, metadata, ...otherOpts  | 
 | 120 | +      } = opts;  | 
 | 121 | +      const data = {  | 
 | 122 | +        title,  | 
 | 123 | +        content,  | 
 | 124 | +      };  | 
 | 125 | +      if (metadata) {  | 
 | 126 | +        try {  | 
 | 127 | +          data.metadata = JSON.parse(metadata);  | 
 | 128 | +        } catch (error) {  | 
 | 129 | +          throw new Error("Invalid JSON for metadata");  | 
 | 130 | +        }  | 
 | 131 | +      }  | 
 | 132 | +      return this._makeRequest({  | 
 | 133 | +        method: "POST",  | 
 | 134 | +        path: "/items",  | 
 | 135 | +        data,  | 
 | 136 | +        ...otherOpts,  | 
 | 137 | +      });  | 
 | 138 | +    },  | 
 | 139 | +    // Update an existing item  | 
 | 140 | +    async updateItem(opts = {}) {  | 
 | 141 | +      const {  | 
 | 142 | +        itemId, updateFields, ...otherOpts  | 
 | 143 | +      } = opts;  | 
 | 144 | +      const data = {};  | 
 | 145 | +      if (updateFields) {  | 
 | 146 | +        try {  | 
 | 147 | +          Object.assign(data, JSON.parse(updateFields));  | 
 | 148 | +        } catch (error) {  | 
 | 149 | +          throw new Error("Invalid JSON for updateFields");  | 
 | 150 | +        }  | 
 | 151 | +      }  | 
 | 152 | +      return this._makeRequest({  | 
 | 153 | +        method: "PUT",  | 
 | 154 | +        path: `/items/${itemId}`,  | 
 | 155 | +        data,  | 
 | 156 | +        ...otherOpts,  | 
 | 157 | +      });  | 
 | 158 | +    },  | 
 | 159 | +    // Add a comment to an existing item  | 
 | 160 | +    async addComment(opts = {}) {  | 
 | 161 | +      const {  | 
 | 162 | +        itemId, commentContent, userDetails, ...otherOpts  | 
 | 163 | +      } = opts;  | 
 | 164 | +      const data = {  | 
 | 165 | +        content: commentContent,  | 
 | 166 | +      };  | 
 | 167 | +      if (userDetails) {  | 
 | 168 | +        try {  | 
 | 169 | +          data.user = JSON.parse(userDetails);  | 
 | 170 | +        } catch (error) {  | 
 | 171 | +          throw new Error("Invalid JSON for userDetails");  | 
 | 172 | +        }  | 
 | 173 | +      }  | 
 | 174 | +      return this._makeRequest({  | 
 | 175 | +        method: "POST",  | 
 | 176 | +        path: `/items/${itemId}/comments`,  | 
 | 177 | +        data,  | 
 | 178 | +        ...otherOpts,  | 
 | 179 | +      });  | 
 | 180 | +    },  | 
10 | 181 |   },  | 
11 | 182 | };  | 
0 commit comments